uplink477 Posted February 20, 2009 Share Posted February 20, 2009 Hi, i have this script that attempts to map a network drive useing DriveMapadd(), iam trying to make it so if the command fails i will get a message as to why, by reading @Error the only problem is @error is never set it always returns 0, weather the command fails or not, any ideas? Here's the Script CODE $drvcall = DriveMapAdd("", "\\192.168.100.1\ADMIN$", 0, "Username", "Psssword") Msgbox(0,"syscall",$drvcall) Msgbox(0,"@error",@error) if $drvcall = 1 then MSgbox(0,"Mapped","Drive Mapped") else Switch @error case "1" MSgbox(0,"error","undefined Error") Msgbox(0,"API Error Code",@extended) case "2" MSgbox(0,"error","access denied Error") Case "3" MSgbox(0,"error","Device already mapped") Case "4" MSgbox(0,"error","Invalid Device NAme") Case "5" MSgbox(0,"error","Invalid remote share") Case "6" MSgbox(0,"error","Invalid Password") EndSwitch EndIf Link to comment Share on other sites More sharing options...
99ojo Posted February 20, 2009 Share Posted February 20, 2009 Hi, i have this script that attempts to map a network drive useing DriveMapadd(), iam trying to make it so if the command fails i will get a message as to why, by reading @Error the only problem is @error is never set it always returns 0, weather the command fails or not, any ideas? Here's the Script CODE $drvcall = DriveMapAdd("", "\\192.168.100.1\ADMIN$", 0, "Username", "Psssword") Msgbox(0,"syscall",$drvcall) Msgbox(0,"@error",@error) if $drvcall = 1 then MSgbox(0,"Mapped","Drive Mapped") else Switch @error case "1" MSgbox(0,"error","undefined Error") Msgbox(0,"API Error Code",@extended) case "2" MSgbox(0,"error","access denied Error") Case "3" MSgbox(0,"error","Device already mapped") Case "4" MSgbox(0,"error","Invalid Device NAme") Case "5" MSgbox(0,"error","Invalid remote share") Case "6" MSgbox(0,"error","Invalid Password") EndSwitch EndIf Hi, try this: DriveMapAdd("", "\\192.168.100.1\ADMIN$", 0, "Username", "Psssword") Switch @error case 0 MSgbox(0,"Mapped","Drive Mapped") case 1 MSgbox(0,"error","undefined Error") Msgbox(0,"API Error Code",@extended) case 2 MSgbox(0,"error","access denied Error") Case 3 MSgbox(0,"error","Device already mapped") Case 4 MSgbox(0,"error","Invalid Device NAme") Case 5 MSgbox(0,"error","Invalid remote share") Case 6 MSgbox(0,"error","Invalid Password") EndSwitch ;-)) Stefan Link to comment Share on other sites More sharing options...
ukmazy Posted February 20, 2009 Share Posted February 20, 2009 or u can just use return @error Link to comment Share on other sites More sharing options...
uplink477 Posted February 20, 2009 Author Share Posted February 20, 2009 (edited) yeah, the script works fine, but everytime there is an error, @error always seems to return 1, even if its ment to return 5 for if the share isnt found or 6 if the password is wrong. Edited February 20, 2009 by uplink477 Link to comment Share on other sites More sharing options...
99ojo Posted February 20, 2009 Share Posted February 20, 2009 yeah, the script works fine, but everytime there is an error, @error always seems to return 1, even if its ment to return 5 for if the share isnt found or 6 if the password is wrong.Hi,just use DriveMapAdd("*", "\\192.168.100.1\ADMIN$", 0, "Username", "Psssword") orDriveMapAdd("x:", "\\192.168.100.1\ADMIN$", 0, "Username", "Psssword");-))Stefan Link to comment Share on other sites More sharing options...
uplink477 Posted February 20, 2009 Author Share Posted February 20, 2009 Hi,just use DriveMapAdd("*", "\\192.168.100.1\ADMIN$", 0, "Username", "Psssword") orDriveMapAdd("x:", "\\192.168.100.1\ADMIN$", 0, "Username", "Psssword");-))StefanThat was not what i was asking, i understand how to use that function, but i cant get any @error codes out of it. Link to comment Share on other sites More sharing options...
jvanegmond Posted February 20, 2009 Share Posted February 20, 2009 yeah, the script works fine, but everytime there is an error, @error always seems to return 1, even if its ment to return 5 for if the share isnt found or 6 if the password is wrong.What is the value of @extended after the function fails? github.com/jvanegmond Link to comment Share on other sites More sharing options...
99ojo Posted February 20, 2009 Share Posted February 20, 2009 (edited) Hi,i used$drvcall = DriveMapAdd("", "\\192.168.100.1\ADMIN$", 0, "Username", "Psssword")@error always return 1if i use $drvcall = DriveMapAdd("*", "\\192.168.100.1\ADMIN$", 0, "Username", "Psssword")then i get other errorcodes, e.g. 5 Invalid remote share;-))Stefan Edited February 20, 2009 by 99ojo Link to comment Share on other sites More sharing options...
ResNullius Posted February 20, 2009 Share Posted February 20, 2009 (edited) @uplink477, In your first post you are testing for the @Error of your Msgbox(0,"syscall",$drvcall) call. This will always be 0. Either use what 99ojo posted in the 2nd post, or modify your code like this to preserve the @Error of DriveMapAdd(). $drvcall = DriveMapAdd("", "\\192.168.100.1\ADMIN$", 0, "Username", "Psssword") $drvCallError = @Error Msgbox(0,"syscall",$drvcall) Msgbox(0,"@error",$drvCallError) if $drvcall = 1 then MSgbox(0,"Mapped","Drive Mapped") else Switch $drvCallError case "1" MSgbox(0,"error","undefined Error") Msgbox(0,"API Error Code",@extended) case "2" MSgbox(0,"error","access denied Error") Case "3" MSgbox(0,"error","Device already mapped") Case "4" MSgbox(0,"error","Invalid Device NAme") Case "5" MSgbox(0,"error","Invalid remote share") Case "6" MSgbox(0,"error","Invalid Password") EndSwitch EndIf Edited February 20, 2009 by ResNullius Link to comment Share on other sites More sharing options...
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