Computer Hope

Microsoft => Microsoft DOS => Topic started by: hope/despair on November 17, 2008, 11:06:25 PM

Title: close explorer to continue scriptt
Post by: hope/despair on November 17, 2008, 11:06:25 PM
Hope this is not a repost but couldn't find anything with my search


My script basically calls for a certain drive to be viewed in explorer (Start z:/) now i need to pause the script until the explorer is closed by the user.
Is it possible?
Title: Re: close explorer to continue scriptt
Post by: Sidewinder on November 18, 2008, 03:32:51 AM
This should work:

Code: [Select]
start /wait explorer z:\

 8)
Title: Re: close explorer to continue scriptt
Post by: hope/despair on November 18, 2008, 09:38:04 AM
I tried that but it doesn't seem to work. Do i need something for the 'wait' to work i.e another script or something?
Title: Re: close explorer to continue scriptt
Post by: Sidewinder on November 18, 2008, 11:15:43 AM
My script basically calls for a certain drive to be viewed in explorer (Start z:/) now i need to pause the script until the explorer is closed by the user.
Is it possible?

Post your script so we can both see the light. Do you actually have a drive z:?

8)
Title: Re: close explorer to continue scriptt
Post by: hope/despair on November 18, 2008, 11:32:02 AM
net use Z: \\madressahserver\test3
Start Z:\
pause
net use Z: /delete
@echo thanks
sleep 5

I want to substitute the pause for the wait function
Title: Re: close explorer to continue scriptt
Post by: Sidewinder on November 18, 2008, 01:07:11 PM
This code should map your z: drive, open explorer and wait; When explorer closes, the z: drive should be deleted from the drive pool and a thank you message displayed on the console.

Code: [Select]
@echo off
net use Z: \\madressahserver\test3
start /wait explorer z:\
net use Z: /delete
echo thanks
sleep 5

Works fine on my machine. Are you sure \\madressahserver\test3 is correct?

 8)
Title: Re: close explorer to continue scriptt
Post by: hope/despair on November 19, 2008, 05:23:33 PM

Quote
Works fine on my machine. Are you sure \\madressahserver\test3 is correct?
 8)

The path is correct

Quote
This code should map your z: drive, open explorer and wait; When explorer closes, the z: drive should be deleted from the drive pool

The explorer opens up but the script continues without waiting for me to close explorer.
I tried start /wait calc.exe and that holds the script until i close calculator... ???
Title: Re: close explorer to continue scriptt
Post by: Sidewinder on November 20, 2008, 05:30:28 AM
Try running the explorer without the start /wait. I cannot reproduce your results, but when I was trying to, I noticed that this works equally well:

Code: [Select]
@echo off
start /wait %comspec% /v:on /c "mode 40,10 & title Login Window & color 1e & echo. & set /p name=Enter Name: &  set /p pswd=Enter password: & cls & echo name=!name!>login.txt & echo pswd=!pswd!>>login.txt & exit"
for /f "tokens=1* delims==" %%i in (login.txt) do (
if %%i==name set name=%%j
if %%i==pswd set pswd=%%j
)
echo Name is %name%
echo Password is %pswd%

net use z: \\madressahserver\test %pswd% /USER:%computername%\%name%
explorer z:
net use z: /delete

I cannot explain why start /wait would work for calc but not explorer.

If the code still fails, a workaround would be to insert a pause statement after explorer launches. This would force the user to hit any key for the batch file to continue. I didn't say it was a great workaround.  ;D

Good luck.

Title: Re: close explorer to continue scriptt
Post by: hope/despair on November 20, 2008, 01:26:48 PM
get this
start /wait z:\file.txt works and holds the script yet start /wait z:\ or start /wait explorer z:\ doesn't
 ???

Title: Re: close explorer to continue scriptt
Post by: Sidewinder on November 20, 2008, 02:57:20 PM
I can't find any documentation referring to this issue. There don't seem to be any settings in explorer that would change this behavior. Might be something deep in the registry, but if it works for you, why not go ahead and use it?

When I try your method, if the file does not exist, explorer defaults to the c: drive and if it does exist, the file opens read-only.

What does the user do when explorer opens? You'd be surprised how imaginative we can be when we have the whole picture.

 8)


Title: Re: close explorer to continue scriptt
Post by: johnsonbben on November 22, 2008, 05:38:01 PM
call explorer.exe Z:\

this should work
Title: Re: close explorer to continue scriptt
Post by: hope/despair on November 22, 2008, 06:35:15 PM
What does the user do when explorer opens? You'd be surprised how imaginative we can be when we have the whole picture.

 8)

the user is going to transfer files in/out or save/edit/open, Now the user's are not neccesarily going to know the file name they are going to be looking for. so i can't have the them type in the file name.

As for the whole picture... I want my script when called upon, to map a drive on the network and open explorer with the mapped drive and when the user closes explorer the script should continue on to disconnect the drive.
Title: Re: close explorer to continue scriptt
Post by: hope/despair on November 22, 2008, 06:40:30 PM
I have been doing a little research and this may or may not be why it's not been working for me.
since explorer is always running in the background when i start explorer it just adds on to the current process (task manager) and thus the script continues. this explains why when i use calc.exe or notepad it's been starting a new process and can track when terminated.

I guess now i need to find out how to start explorer in a seperate process. any ideas?
Title: Re: close explorer to continue scriptt
Post by: Sidewinder on November 23, 2008, 05:33:26 AM
Quote
I guess now i need to find out how to start explorer in a seperate process. any ideas?

Not a one. As the file manager application in Windows, I suspect Explorer was written not to allow multiple copies of itself and that all requests would attach to the single running instance.

Window tasks by definition open in their own window, so using start is probably over kill. The start command was designed to run console applications in another window. The /wait switch determines whether the batch file continues or waits.

In your system the batch file never waits and continues to run whether Explorer is launched with start or run inline. I still am not able to duplicate your results, on XP or Vista.

Perhaps someone wiser will come by with a solution. 8)

Note: a previous post suggested using call. Call is used to transfer control to external batch file or an internal subroutine. It also sets up a return address back to the next sequential instruction after the call. Call works internal to the current shell program context, start works external to the current shell program context.
Title: Re: close explorer to continue scriptt
Post by: hope/despair on November 23, 2008, 10:19:32 AM
If possible, could you check if task manager shows two processes of explorer.exe when you open explorer through  command prompt?
Appreciate all your help
Title: Re: close explorer to continue scriptt
Post by: Sidewinder on November 23, 2008, 11:48:49 AM
As the file manager application in Windows, I suspect Explorer was written not to allow multiple copies of itself and that all requests would attach to the single running instance.

I may have been a tad wrong misguided with my suspicions. :o Starting explorer with start /wait or inline results in two copies of explorer running. However, the batch file continues to wait for explorer to end.
 
Interesting to note:

Batch file copy: high priority using 20 MB
System copy: normal priority using 35MB

Normally explorer lives in the Windows directory. Any chance there is another copy in your path? Just asking. 8)

My copy of explorer is dated 4/14/2008 and seems to work as advertised. This gets curiouser and curiouser!