Jump to content

Help with external program


 Share

Recommended Posts

:P

Can someone help me with why I am getting the error message "The system cannot find the path specified." when I use the run command?

What I am trying to do is map a drive and then run a program from the mapped drive location. I am able to successfully map the drive, but when I go to execute the program, I get the above error message.

$username = 'user1'
$password = 'password1'
$server = '\\172.29.10.29\ldlogon'

;Find the first unused drive letter
$drive = StringSplit("c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z",",",1)
For $i = 1 to $drive[0] step +1
    $var = DriveStatus( $drive[$i] & ":" )
    If $var = "INVALID" Then 
        $AvailDrive = $drive[$i]
    EndIf
Next

;Map available drive letter to program folder on server
DriveMapAdd($AvailDrive & ":", $server, 0, $username, $password)
Run($AvailDrive & ":\HATScanner.exe", $AvailDrive & ":\", @SW_MAXIMIZE)
Exit

Is it because the 'filename' and 'working dir' parameters are not totally inclused in quotes?? :D

Link to comment
Share on other sites

OK...I've even tried this:

$Filename = $AvailDrive & ":\HATScanner.exe"
$WorkingDir = $AvailDrive & ":\"
Run($Filename, $WorkingDir, @SW_MAXIMIZE)

...and I'm still getting an error message - "==> Unable to execute the external program.: Run($Filename, $WorkingDir, @SW_MAXIMIZE)

The system cannot find the path specified."

What am I not going right?? :P

Link to comment
Share on other sites

Check the return value (and @error if it is equal to 0 ) of DriveMapAdd. Also, hard code the path, just to make it sure it works like,

Run("B:\HATScanner.exe", "B:\")

-John

OK...I've done both and I still get the error message.

I added the following code:

DriveMapAdd($AvailDrive & ":", $server, 0, $username, $password)
If @error = 0 Then MsgBox(64, "ERROR", $AvailDrive & " is already mapped.")
If @error = 1 Then MsgBox(16, "ERROR", "Undefined/Other error.")
If @error = 2 Then MsgBox(16, "ERROR", "Access to the remote share was denied.")
If @error = 3 Then MsgBox(64, "WARNING", "The device is already assigned.")
If @error = 4 Then MsgBox(16, "ERROR", "Invalid device name.")
If @error = 5 Then MsgBox(16, "ERROR", "Invalid remote share.")
If @error = 6 Then MsgBox(16, "ERROR", "Invalid password.")

...and when I run the script, I always get @error =0!!! On my PC, the first available drive always comes up as "Y:" and I can see "verify" that the Drive MapAdd command is successful because I get a drive map to Y and I can access the files from that location through explorer. What I don't understand is why then do I always get the @error returning as 0, telling me that the map was not successful, when I can see that it was successful? :D

I then hard coded it was well...

Run("Y:\HATScanner.exe", "Y:\", @SW_MAXIMIZE)

...and it still comes back with the same error message.

I also noted, by adding a cmd.exe call to the script...

RunWait("cmd.exe", "C:\Windows\System32", @SW_MAXIMIZE)

...I am unable to access the "Y:" drive from the command window and it produces an error of: "The system cannot find the drive specified."

I'm not sure what to do from here. :P

Link to comment
Share on other sites

For now, I would try mapping the drive with "net use y: \\server\sharename" and then comment out the DriveMapAdd() command. You script should then only have the Run() command as the very 1st line of the program. You can also see what's going on by using FileMon.

-John

Edited by jftuga
Link to comment
Share on other sites

For now, I would try mapping the drive with "net use y: \\server\sharename" and then comment out the DriveMapAdd() command. You script should then only have the Run() command as the very 1st line of the program. You can also see what's going on by using FileMon.

-John

John,

I'm not sure about what you mean by having the "Run() command as the very 1st line of the program"? Please explain.

OK...this is what I now have:

$username = 'user1'
$password = 'password1'
$server = '\\172.29.10.29\ldlogon'

$drive = StringSplit("c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z",",",1)
For $i = 1 to $drive[0] step +1
    $var = DriveStatus( $drive[$i] & ":" )
    If $var = "INVALID" Then 
       ;MsgBox(1,"Free:","The first free letter: " & $drive[$i])
        $AvailDrive = $drive[$i]
    EndIf
Next

$ExtCmd = "NET USE " & $AvailDrive & ": \\172.29.10.29\ldlogon /USER:homer 1nth3m@tr1x"
$RetCode = RunWait($ExtCmd, @TempDir, @SW_MINIMIZE)
If $RetCode = 0 Then
     MsgBox(64, "Success", "Successfully mapped " & $AvailDrive & ": drive.")
Else
     MsgBox(16, "Error", "Error mapping " & $AvailDrive & ": drive, ERRORLEVEL = " & $RetCode)
EndIf

$Filename = $AvailDrive & ":\HATScanner.exe"
$WorkingDir = $AvailDrive & ":\"
Run($Filename, $WorkingDir, @SW_MAXIMIZE)

Exit

...and I'm getting the error message:

Run($Filename, $WorkingDir, @SW_MAXIMIZE)

The parameter is incorrect.

If I hard code it...

Run("Y:\HATScanner.exe", "Y:\", @SW_MAXIMIZE)

...I still get an error message:

Run("Y:\HATScanner.exe", "Y:\", @SW_MAXIMIZE)

The parameter is incorrect.

Any help with what I should do next?

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...