Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

OS Detection + Password hiding

Status
Not open for further replies.

phboujon

Programmer
Jan 20, 2003
2
AU
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
 
1) you can use "comSpec" environment variable that contains exactly what you want. It exists on NT and XP but as I don't have a win9x here, I can't tell you if it exists in these OS. You can get this way :
Code:
Set WshShell = WScript.CreateObject("WScript.Shell")
Set WshSysEnv = WshShell.Environment("SYSTEM")
WScript.Echo WshSysEnv("COMSPEC")


Water is not bad as long as it stays out human body ;-)
 
try and get away from using shell commands and outputting to files that you then have to read back in again.
that way, in this instance you wouldnt be concerned about the OS, ok maybe you might want to know about it later for other reasons but....

Set refWMIService = GetObject("winMgmts:")
Set colSmallFiles = refWMIService.ExecQuery(&quot;SELECT * FROM CIM_DataFile WHERE FileSize < '1024'&quot;)

This would return a standard 'collection' of files smaller than 1024. you could change this to be ones with doc,xls etc extensions. you could then manip this collection in the standard ways

the above it using WMI with a WQL query (similar to SQL i guess)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top