Sign in to follow this  
Followers 0
uplink477

DriveMapAdd() @error not reporting

9 posts in this topic

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

Share this post


Link to post
Share on other sites



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

Share this post


Link to post
Share on other sites

or u can just use return @error

Share this post


Link to post
Share on other sites

#4 ·  Posted (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 by uplink477

Share this post


Link to post
Share on other sites

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") or

DriveMapAdd("x:", "\\192.168.100.1\ADMIN$", 0, "Username", "Psssword")

;-))

Stefan

Share this post


Link to post
Share on other sites

Hi,

just use DriveMapAdd("*", "\\192.168.100.1\ADMIN$", 0, "Username", "Psssword") or

DriveMapAdd("x:", "\\192.168.100.1\ADMIN$", 0, "Username", "Psssword")

;-))

Stefan

That was not what i was asking, i understand how to use that function, but i cant get any @error codes out of it.

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Hi,

i used

$drvcall = DriveMapAdd("", "\\192.168.100.1\ADMIN$", 0, "Username", "Psssword")

@error always return 1

if 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 by 99ojo

Share this post


Link to post
Share on other sites

#9 ·  Posted (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 by ResNullius

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0