Abracetti Posted August 19, 2008 Posted August 19, 2008 Hi , I'm quite new to autoit scripts however i played with the codes a little bit to try getting some of admin tasks automated in exe file that i could deploy to users machines. The following code should map a network drive and run a vbs script to defrag the C: of the machine , using admin credentials. Whats is confusing me is that the drive is being mapped but when i do "net use" it comes up as unavaiable, this only happens when inside the execution of this autoit file , if i go to cmd and do net use J: \\myserver\scripts it does map it properly and it becomes available. Having the mapped drive unavailable stops me from running the script i want because it won't find it. any help would be very welcome. ********************************************************************************** Local $sUserName = "administrator" Local $sPassword = "mypassword" Local $sDomain = "mydomain" Run(@ComSpec&" /c "& 'net use J: \\myserver\scripts', "", @SW_HIDE) Local $pid = RunAsWait($sUserName, $sDomain , $sPassword, 1,"CSCRIPT J:\XDefrag.vbs /L", @ComSpec) ;Wait for the process to close. ProcessWaitClose($pid) MsgBox(0, "Defrag Finished?",$pid) Run(@ComSpec & " /c " & 'net use J: /delete', "", @SW_HIDE) MsgBox(0, "Process Finished", "J Drive unmapped"); ************************************************************************************
Anteaus Posted August 19, 2008 Posted August 19, 2008 Run(@ComSpec&" /c "& 'net use J: \\myserver\scripts', "", @SW_HIDE) I think your problem is most likely that the NET USE command will be asking for a username and password, but of course you never see its console window. You can add ' /user:[username] [password]' to the commandline. Alternatives are to use the DriveMapAdd() command which is the Autoit-native method, or to: Use RunAsSet to determine the credentials the process will run under, and then use a UNC path to access the server. If the local credentials match a server-account there should be no need to repeat them.
Abracetti Posted August 21, 2008 Author Posted August 21, 2008 Took me quite a while to find the answer , probably because I'm a newbie but I finally resolved the issue just by doing the command: Local $pid1 = RunAsWait($sUserName,$sDomain,$sPassword,1, @COMSPEC & " /c \\myserver\scripts\defrag.vbs",@WindowsDir,@SW_HIDE) ProcessWaitClose($pid1) Don't even need to map the drive Of course there is a shared drive called \\myserver\scrpits Thanks for the attention
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now