Hi, I am new at VbScript so if that's easy questions, sorry, but for me it isnt . Thanks for any help you could provide me.
I am writing a VBScript application which is trying from a Windows 95/98/NT4/2000/XP PC, to copy files with specific
extensions, (e.g. *.DOC *.XLS *.PPT) to a user's home directory on a Windows 2000 server. The PC may or may not be logged onto a Windows NT 4 domain, so some sort of authentication prompt may be required.
I have severals problems on this application:
1) How can I detect the Operation System in use on the computer? I need to use the 'cmd.exe' or 'command.exe' as shell, so I need to kow if am under Win95/98 or later.
2) I would like to hide the password when it is entered (you know, like having asterisks).
3) Right now, I am doing kind of a stupid stuff (comment and uncomment line when needed) to be able to map the drive (cf code), so I would like to map the drive first, and if it fails (User not logged), asked for login and pass, and map again.
4) oNet.MapNetworkDrive sMapDrive statement isnt working on Win95, as it complains that the network is never started.
CODE:
Dim oFSO, oDrive, oAllDrives, oTextStream
Dim sCmd, sFileName, vFileTypes, sFileTypes, sFileType
Dim iTypeCount
'-- File I/O
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8
Const DRIVETYPE_HDD = 2
'-- Specify the types of files to search for here
sFileTypes="*.doc,*.xls,*.ppt"
vFileTypes = split(sFileTypes,","
Set oShell = CreateObject("WScript.Shell"
Set oFSO = CreateObject("Scripting.FileSystemObject"
Set oNet = CreateObject("WScript.Network"
sMapDrive="X:" '-- Change the network drive letter as required
'Here is my question 3 and 2 problem
'-- Get the username and password
sUserName = InputBox("Please enter your user account","User Account Required"
sPassword = InputBox("Please enter your account password","Account Password Required"
oNet.MapNetworkDrive sMapDrive, "\\Jamaca\home", False, sUserName, sPassword
'-- If the users are already authenticated to the network (i.e. Have already logged on), you can comment
'-- out the three lines above to prevent users being prompted for username and password.
'-- Make a connection to the users home folder
'oNet.MapNetworkDrive sMapDrive, "\\Jamaca\home", False
'-- If the users are already authenticated to the network (i.e. Have already logged on), you can uncomment
'-- the line above to do pass-through authentication when making the network drive connection.
Set oAllDrives = oFSO.Drives
For Each oDrive in oAllDrives
If oDrive.DriveType = DRIVETYPE_HDD Then '-- Look at fixed drives only
If isarray(vFileTypes) Then
For iTypeCount = 0 To Ubound(vFileTypes)
sFileType = vFileTypes(iTypeCount)
WScript.Echo "Searching Drive " & UCase(oDrive.DriveLetter) & ": for files of type " & sFileType & " ..."
Here is my question 1 problem
sCmd = "cmd /C Dir /s /B " & oDrive.DriveLetter & ":\" & sFileType & " > SearchResult.txt"
oShell.Run sCmd, 0, True
set oTextStream = oFSO.OpenTextFile("SearchResult.txt",ForReading,False)
Do While Not oTextStream.AtEndOfStream
sFileName = oTextStream.ReadLine
If oFSO.FileExists(sFileName) Then
Wscript.Echo "Copying File -- " & sFileName
sDestination = sMapDrive & "\Backup\" '-- Set your destination path here !!!
oFSO.CopyFile sFileName, sDestination, True
End If
Loop
Next
End If
End If
Next
oNet.RemoveNetworkDrive sMapDrive
I am writing a VBScript application which is trying from a Windows 95/98/NT4/2000/XP PC, to copy files with specific
extensions, (e.g. *.DOC *.XLS *.PPT) to a user's home directory on a Windows 2000 server. The PC may or may not be logged onto a Windows NT 4 domain, so some sort of authentication prompt may be required.
I have severals problems on this application:
1) How can I detect the Operation System in use on the computer? I need to use the 'cmd.exe' or 'command.exe' as shell, so I need to kow if am under Win95/98 or later.
2) I would like to hide the password when it is entered (you know, like having asterisks).
3) Right now, I am doing kind of a stupid stuff (comment and uncomment line when needed) to be able to map the drive (cf code), so I would like to map the drive first, and if it fails (User not logged), asked for login and pass, and map again.
4) oNet.MapNetworkDrive sMapDrive statement isnt working on Win95, as it complains that the network is never started.
CODE:
Dim oFSO, oDrive, oAllDrives, oTextStream
Dim sCmd, sFileName, vFileTypes, sFileTypes, sFileType
Dim iTypeCount
'-- File I/O
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8
Const DRIVETYPE_HDD = 2
'-- Specify the types of files to search for here
sFileTypes="*.doc,*.xls,*.ppt"
vFileTypes = split(sFileTypes,","
Set oShell = CreateObject("WScript.Shell"
Set oFSO = CreateObject("Scripting.FileSystemObject"
Set oNet = CreateObject("WScript.Network"
sMapDrive="X:" '-- Change the network drive letter as required
'Here is my question 3 and 2 problem
'-- Get the username and password
sUserName = InputBox("Please enter your user account","User Account Required"
sPassword = InputBox("Please enter your account password","Account Password Required"
oNet.MapNetworkDrive sMapDrive, "\\Jamaca\home", False, sUserName, sPassword
'-- If the users are already authenticated to the network (i.e. Have already logged on), you can comment
'-- out the three lines above to prevent users being prompted for username and password.
'-- Make a connection to the users home folder
'oNet.MapNetworkDrive sMapDrive, "\\Jamaca\home", False
'-- If the users are already authenticated to the network (i.e. Have already logged on), you can uncomment
'-- the line above to do pass-through authentication when making the network drive connection.
Set oAllDrives = oFSO.Drives
For Each oDrive in oAllDrives
If oDrive.DriveType = DRIVETYPE_HDD Then '-- Look at fixed drives only
If isarray(vFileTypes) Then
For iTypeCount = 0 To Ubound(vFileTypes)
sFileType = vFileTypes(iTypeCount)
WScript.Echo "Searching Drive " & UCase(oDrive.DriveLetter) & ": for files of type " & sFileType & " ..."
Here is my question 1 problem
sCmd = "cmd /C Dir /s /B " & oDrive.DriveLetter & ":\" & sFileType & " > SearchResult.txt"
oShell.Run sCmd, 0, True
set oTextStream = oFSO.OpenTextFile("SearchResult.txt",ForReading,False)
Do While Not oTextStream.AtEndOfStream
sFileName = oTextStream.ReadLine
If oFSO.FileExists(sFileName) Then
Wscript.Echo "Copying File -- " & sFileName
sDestination = sMapDrive & "\Backup\" '-- Set your destination path here !!!
oFSO.CopyFile sFileName, sDestination, True
End If
Loop
Next
End If
End If
Next
oNet.RemoveNetworkDrive sMapDrive