Jump to content

Pushd Command


Recommended Posts

I tried running the following command and I get can't find program, though I can

run the command from the command prompt dos window with no problem.

Please advise.

Command attempting to run: RunWait('pushd \\engwin2\util')

Without the run wait this will automatically map a drive letter with the latest availabe letter.

Thanks to all.

Link to comment
Share on other sites

  • Developers

what about? RunWait(@comspec & '/c pushd \\engwin2\util')

Edited by JdeB

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • Developers

also make sure to use a space before the /c as in

Good:

RunWait(@comspec & ' /c pushd \\engwin2\util')

Bad:

RunWait(@comspec & '/c pushd \\engwin2\util')
yeap, you are right! there's a space missing before the /c in my post ! :whistle:

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Two suggestions

First, try running a command window and then sending your commands as key strokes to the command window:

run(@ComSpec)
WinWaitActive(@ComSpec)
send("pushd \\engwin2\util{ENTER}")
sleep(250)

(the sleep is there to allow the command to complete before issuing your next command. You will have to adjust the time as appropriate)

Second, the help for PUSHD states the Command Extensions must be enabled to allow network paths to be accepted. Although cmd.exe (at least on Win 2K) is supposed to enable Command Extensions by default, you could try explicitly enabling them using

RunWait(@comspec & ' /E:ON /c pushd \\engwin2\util')

GrahamS

Link to comment
Share on other sites

Function DriveGetType will set @Error to 1 if the drive doesn't exist (and returns the drive type if it does).

PUSHD help states that it creates a temporary drive for the network path and that the temporary drive letters are allocated from Z: on down, using the first unused drive letter found.

You could use DriveGetType in a for loop to find the "highest" unused drive letter first, run your pushd command, and then check that the previously found drive letter is now mapped to a network drive

Sorry, but I cannot test this at the moment - no network

GrahamS

Link to comment
Share on other sites

To get the drive, just send something to a temp file, as in.

Run(@ComSpec)
WinWaitActive(@ComSpec)
send("pushd \\engwin2\util{ENTER}")
sleep(250)
$file="temp.txt"
$file2=@TempDir&"\"&$file
send("dir >"&@TempDir&"\"&$file&"{enter}")

While FileExists ($file2)=0
    sleep(100)
Wend
winclose(@ComSpec)
$file = FileOpen($file2, 0)
     $line = FileReadLine($file2)
$drive=StringMid ($line,StringInStr ($line,"drive ")+6,1) 
     MsgBox(0, $line,$drive)
FileClose($file2)
FileDelete($file2)

Sloppy, but effective. Sorry only tested on WinXP atm.

AutoIt3, the MACGYVER Pocket Knife for computers.

Link to comment
Share on other sites

  • 2 weeks later...

Yea, net use makes it a bit simpler, and can do it in backround.

for $i=90 to 65 step -1; Capital Z-A in Chr()
$Status = DriveStatus( Chr($i)&":\" )
if $Status="Invalid" then; checks if already assigned
$driveX=Chr($i)
$err=runwait(@comspec & " /c net use "& $driveX &": \\engwin2\util","",@SW_HIDE)
exitloop
endif
next
if $err=0 then 
msgbox(1,$err& " info","\\engwin2\util mapped to " & $driveX)
else
msgbox(1,$err& "Error","Cannot map drive to \\engwin2\util")
endif

AutoIt3, the MACGYVER Pocket Knife for computers.

Link to comment
Share on other sites

Hmm, on my system, I keep the drive letter even after exiting the window, Win2k Pro.

My Popd created Z drive stays there until I disconect it.

I will test it on other OS soon.

You're right, ScriptKitty. :whistle:

I just verified that in Win2K it disconnects all pushd'd drives when the cmd window closes. B) In WinXP it leaves it. :evil:

Might want to code for both OSes if you have a mix. Use a 'net use' command. Or better yet they could build in a drive mapping command. :angry:

Link to comment
Share on other sites

Guest Platrix

I had an similar problem and have writen a special script for them:

it checks for first aviable drive letter after "c"

$drive = drivegetdrive("all")
$map = 0
for $i = 2 to $drive[0] - 1
     if asc($drive[$i + 1]) - asc($drive[$i]) > 1 then
     $map = chr(asc($drive[$i]) + 1) & ":"
     exitloop
endif
next
if $map = 0 then $map = chr(asc($drive[$i]) + 1) & ":"

runwait(@comspec & " /c " & "net use " & $map & " \\server\share\", "", @sw_hide)

...

runwait(@comspec & " /c " & "net use " & $map & " /d", "", @sw_hide)
Link to comment
Share on other sites

FYI: The "/PERSISTENT:YES" command-line argument may be used to specify the drive mapping is to become permanent. (Until manually disconnected)

Likewise "/PERSISTENT:NO" may also be used to specify the drive mapping is to only be designated for the current boot.

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...