# PUSHD & POPD in batch not working



## er.loyaamit

Hi, I have created a .bat script.

-----------------------------
@echo off

pushd \\192.168.137.10\IPexe 
cd IP
ipinve.exe
popd 

pushd \\192.168.137.10\IPexe 
cd Hardware
hardware.exe 
popd 

pushd \\192.168.137.10\IPexe 
cd Software
softwareinventory.exe
popd 

--------------------------------------------


This is script collects inventories from users machine, with .exe setup's as ,"ipinve.exe","hardware.exe","softwareinventory.exe". I wanna map drive to users machine using PUSHD command. "IPexe is thte folder which contains all the .exe files mentioned above."I copied script into startup of server 2003.Users m/c r running XP sp3. When user machine boots up, this startup script not working, with no log in event viewer. when i try 2 execute the above script manually on users machine , it works fine, with inventory details in respective folder.

I think something wrong with above script.

Help needed.


----------



## TheOutcaste

er.loyaamit said:


> I copied script into startup of server 2003.


You put the script into the startup folder on the Win2k3 server, or you created a Group Policy for the Domain, and set this as a Startup script?
This would be located in this folder:


Code:


\\<DomainName>\sysvol\<DomainName>\Policies\{GUID for Default Domain Policy}\Machine\Scripts\Startup

The sysvol share is usually *C:\Windows\SYSVOL\sysvol*, unless you moved the location of the SYSVOL folder.

You can specify a script in any location of course, but it may not be replicated to other DCs if not in the SYSVOL tree.

Redirect STDERR and STDOUT to a log file, then you can see what errors occurred:
On the client, create this folder: *C:\Test*

Add this as a parameter for the script in Group Policy:
*>>C:\Test\Scriptlog.txt 2>&1*

Boot the client, then check the *C:\Test\Scriptlog.txt* to see what errors occurred if any. It's likely Access Denied.

I've not been able to use the IP address in a Startup script, but it's works fine using the Server Name


----------



## Squashman

Just a side note: 
Doing the pushd and popd 3 times is just slowing down your script. Why are doing it that way?


----------



## er.loyaamit

I changed the script & tried it, then also it is not working. Added DisableUNCcheck = 1 in registry, not working. 

Finally after working a lot on it i found, When i run the script with Domain administrator rights on local machine it works fine. Also when i copy the script on local machine it runs fine. And i tried running it manually, added a pause in script it shows, "UNC not supported ....". I think PUSHD 's main purpose is 2 support UNC mapping only...then also why it is not working ??

---------------------------------

@ New modified script

@echo off


pushd \\\192.168.137.10\IPexe 
cd IP
ipinve.exe

cd..
cd Hardware
hardware.exe 

cd..
cd Software
softwareinventory.exe

popd


----------



## TheOutcaste

Are you deploying the script using the Domain Group Policy?
Are you running this as a *Startup* script, or a *Logon* Script?
What are the NTFS permissions on the *IPexe* share?
What are the Share permissions on the *IPexe* share?

You shouldn't need the *DisableUNCCheck* registry entry. You'll still get the message, but PushD should still work.
Are you adding *DisableUNCCheck* under Current User, or Local Machine?
I don't have that entry, and this is what I get when I run my Test file manually:



Code:


'\\Win2k3-ent\SYSVOL\test.Domain.local\Policies\{31B2F340-016D-11D2-945F-00C04FB984F9}\MACHINE\Scripts\Startup'
CMD.EXE was started with the above path as the current directory.
UNC paths are not supported.  Defaulting to Windows directory.

C:\WINDOWS>[B][COLOR=Red]PushD \\Win2k3-ent\UserData1

Z:\>[/COLOR][/B]MD TestFolder

Z:\>Echo.Hello World 1>Test.txt

Z:\>Call Z:\ExefromStartup.cmd

Z:\>Dir /A  1>Z:\CurrentDir.txt

Z:\>PopD

C:\WINDOWS>Pause
Press any key to continue . . .

You'll notice the *Pushd* Command did assign the letter *Z:* to the UNC Path. The error does not occur when the script is executed at boot.

Did you add the parameters to redirect the output to a log file on the client (*C:\Test\Scriptlog.txt*)? Adding Pause statements won't help, as there will be no visible window for a Startup script, as it runs under the Local System account. You'll also have to use Task Manager to end task on the process as you won't be able to press Enter to continue.

What is in the *C:\Test\Scriptlog.txt* file? (This will be on the Client, not the Server)
This is what I get.
The called program runs, but can't create the output file.
The other commands fail, as Authenticated Users do not have Write access to the share.
(The above succeeded as it was manually run from an Admin Account).
*C:\Test\Scriptlog.txt*


Code:


C:\WINDOWS>PushD \\Win2k3-ent\UserData1 

Z:\>MD TestFolder 
Access is denied.

Z:\>Echo.Hello World 1>Test.txt 
Access is denied.

Z:\>Call Z:\ExefromStartup.cmd 

Z:\>Dir /A  1>Z:\CurrentDir.txt 
Access is denied.

Z:\>PopD

C:\WINDOWS>Pause
Press any key to continue . . .

If I give *Authenticated Users* NTFS *Modify*, and Share *Change* permissions, it works fine (removed the Pause statement as well:
*C:\Test\Scriptlog.txt*


Code:


C:\WINDOWS>PushD \\Win2k3-ent\UserData1 

Z:\>MD TestFolder 
A subdirectory or file TestFolder already exists.

Z:\>Echo.Hello World 1>Test.txt 

Z:\>Call Z:\ExefromStartup.cmd 

Z:\>Dir /A  1>Z:\CurrentDir.txt 

Z:\>PopD

I get the same result logging on to the client with a Domain Admin account and a Standard User account, The script is set as a Startup script.
Startup script:


Code:


PushD \\Win2k3-ent\UserData1
MD TestFolder
Echo.Hello World>Test.txt
Call %CD%ExefromStartup.cmd
PopD

\\Win2k3-ent\UserData1\ExefromStartup.cmd


Code:


Dir /A >%CD%CurrentDir.txt


----------

