#145940 - 2005-08-18 06:33 PM
USE and variables
|
plut0
Lurker
Registered: 2005-08-18
Posts: 2
|
I cannot seem to get the "USE" command to work with variables. If I try typing net use in a command prompt, it works. If I try typing out the command without variables in my script, it works. But it does not work with variables.
Heres part of my code: Code:
$string = '* "' + $share + '" ' + '/user:' + $user + ' /persistent:yes' Use $string ? "Result: " + @RESULT + ", Error: " + @ERROR
This script is called from another script (I'm doing this to run it as an admin instead of a normal user).
Code:
$RunAsLocalAdmin = 'lsrunase.exe /user:admin /domain:@WKSTA /password:encrypted ' Shell $RunAsLocalAdmin + '/runpath:' + $runpath + ' /command:"kix32.exe network.kix $share=\\server\share $user=nobody"'
I have echoed the variable $string before the USE statement and it looks fine to me, even has the quotes around the share name. There is no result returned, obviously, and the error returned is 67. I have also tried using: Execute( 'USE $string' ), but that didn't work either. I am quite stumped, anyone have any ideas?
Thanks for the assistance.
|
|
Top
|
|
|
|
#145941 - 2005-08-18 07:14 PM
Re: USE and variables
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
The reason you are failing is that the USE command does not take a single string as input. USE requires separate in parameters (Drive, Path, Options (individual)).
See the following code sample: Code:
Function MapDrive($Drive, $Server, $Share) Dim $Drive, $Server, $Share, $shell Color c+/n
If $Drive<>"" and $Server<>"" and $Share<>"" $LogText="Connecting $Drive to \\$Server\$Share" ? $LogText USE $Drive /Delete /Persistent USE $Drive "\\$Server\$Share" If @error=0 color g+/n $x=" - Success" "$x" If val($DOS) >= 5 $shell=createobject("shell.application") $shell.namespace($Drive+"\").self.name=$Share + " on '" + $Server + "'" $shell = 0 Endif Else color r+/n $x=" - Failed: Error @error" "$x" $ErrorState=1 Endif WriteLog ($LogText + $x) WriteLog2("%temp%\MapDrive.log",$LogText + $x,1) Color w+/n Else WriteLog ("Function 'MapDrive' called with invalid parameters: '$Drive', '$Server', '$Share'") Endif Endfunction
|
|
Top
|
|
|
|
#145942 - 2005-08-18 07:17 PM
Re: USE and variables
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
Also there is no "yes" associated with the USE command.
From the manual:
USE LIST USE < * | "device" | "resource"> /DELETE [/PERSISTENT] USE ["device"] <"resource"> [/USER:user] [/PASSWORD:password] [/PERSISTENT]
|
|
Top
|
|
|
|
#145943 - 2005-08-18 09:33 PM
Re: USE and variables
|
plut0
Lurker
Registered: 2005-08-18
Posts: 2
|
Thanks Howard, your solution pointed me in the right direction. I was having issues with the quotes and such. I tried this one line from your code, USE $Drive "\\$Server\$Share", this did not work. However, this did:
Code:
$share = "\\server\share" Use * $share /user:$user
I'm not sure why your code doesn't work for me but you helped me fix the problem. Thanks!
|
|
Top
|
|
|
|
#145944 - 2005-08-18 09:47 PM
Re: USE and variables
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
If you want to know why something doesn't work check the error response.
Code:
$Drive = "H:" $Server = "MyServer" $Share = "Sharename" USE $Drive "\\" + $Server + "\" + $Share ? "Error Code = " + @error ? "Error text = " + @serror
But since you use the user option my guess is that you you have not set up domain security the way I have.
I think using the "*" for the drive is problematic and discourage its use.
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 962 anonymous users online.
|
|
|