Login | |
|
 |
Re: SOLVED - Quick syntax question - 5/13/2005 4:45:11 AM
|
|
 |
|
| |
Country73
Posts: 733
Score: 10
Joined: 8/25/2004
From: USA
Status: offline
|
This worked out just fine for me: Set WshNetwork = WScript.CreateObject("WScript.Network") DriveLetter = "X:" sNetPath = "\\server\share" WshNetwork.MapNetworkDrive DriveLetter, sNetPath
|
|
| |
|
|
|
 |
Re: SOLVED - Quick syntax question - 5/13/2005 6:21:39 AM
|
|
 |
|
| |
kirrilian
Posts: 628
Score: 3
Joined: 3/15/2005
From:
Status: offline
|
how about posting the whole script?
|
|
| |
|
|
|
 |
Re: SOLVED - Quick syntax question - 5/13/2005 6:39:50 AM
|
|
 |
|
| |
Caer
Posts: 29
Score: 0
Joined: 4/26/2005
From: USA
Status: offline
|
Ok here is the whole script: Dim WshShell, objFSO, sUser, sPass, sNetPath ' ** sUser is the Username ' ** sPass is the Users password ' ** sCommand is the command that you want run ' ** sNetPath is the path to the server\share ' ** You can replace these string variables to any user/password/command ' ** combo that you need to run on a pc. ' ** NOTE: If you change the sPass field be sure to retain the ' ** quotes and the ~ at the end of the actual password, it ' ** is the carriage return character. sUser = "username@domain.net" sPass = "UserPassword~" sNetPath = "\\server\share\" ' ** USAGE: sCommand = "wscript " <path_to_command> "<your_script_here.vbs" ' ** or you can write in any command that needs to be run under ' ** a specific users account. sCommand = "wscript " & sNetPath & "changepassword.vbs" ' ** This is where we setup the working environment for the script to run in. Set objComputer = CreateObject("Shell.LocalMachine") Set WshNetwork = CreateObject("WScript.Network") Set WshShell = CreateObject("WScript.Shell") Set WshEnv = WshShell.Environment("Process") WinPath = WshEnv("SystemRoot")&"\System32\runas.exe" Set objFSO = CreateObject("Scripting.FileSystemObject") '** Here we will check to see if this script has run on this computer. '** If the file exist then we will end the script. If objFSO.FileExists("C:\ScriptLog.txt") Then WScript.Quit Else ' ** Here we map a network drive to our server\share. DriveLetter = getNextDriveLetter WScript.Echo driveletter, sNetPath WshNetwork.MapNetworkDrive DriveLetter, sNetPath ' ** This is the meat of the program and where the actual command is run. rc = WshShell.Run ("runas /noprofile /user:" & sUser & " " & Chr(34) & sCommand & Chr(34)) ' ** This gives the command window the time to open. WScript.Sleep 900 ' ** This will grab the active command window to send the password to. WshShell.AppActivate(WinPath) ' ** This will send the password to the waiting window. WshShell.SendKeys sPass ' ** Here we write a .txt file to the root of c: for verification that the script ' ** has been run on this computer. Set objFile = objFSO.CreateTextFile("C:\ScriptLog.txt") ' ** Here we open the Finished.txt and append the name of the computer ' ** that was just changed and the date it happened. Set objTextFile = objFSO.OpenTextFile(DriveLetter & "\Finished.txt", 8, True) objTextFile.WriteLine(objComputer.MachineName) & " " & Date() & " " & Time() & " " & (WshNetwork.UserName) objTextFile.Close ' ** Now we will remove the mapped drive WshNetwork.RemoveNetworkDrive DriveLetter End If '** This function finds the next available drive letter '** and returns it to the DriveLetter variable Function getNextDriveLetter Dim drive, drives, temp drives = "C D E F G H I J K L M N O P Q R S T U V W X Y Z" For Each drive In objFso.Drives drives = Trim(Replace(drives,Left(drive,1),"")) Next temp = Left(drives,1) & ":" getNextDriveLetter = temp End Function '** All Done :) WScript.quit ------------------------------------------------------------ Before i wasn't using the sNetPath variable, i was just using a "\\server\share" string in quotes and it worked great, but since this script is for a company that i'm contracted by i want to use variables so that if they need to make changes it will be easier for them. Thanks, Caer ><
|
|
| |
|
|
|
|
|