Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Windows 7 batch file not working

Status
Not open for further replies.

ETPC

Technical User
Dec 21, 2011
4
US
I have two PC's, one with Windows 7 Pro 32 bit and the other with XP Pro 32 bit. My family members use both PC's so I have identical accounts set up on both. I made a shared drive on both so that any of us could drop a file from one PC to the other. I wrote a batch file with the "NET USE" command to run on the XP PC any time a user logs in to map the shared drive of the other PC and it works great. The problem is the batch file won't work on the Windows 7 PC. When I tried to run it I get an error that says the the file isn't a valid Windows eternal or internal command, or batch file. What do I have to do get this batch file to work?
 
you need to have the batch file run with elevated user privileges...

regular users are not allowed to run CMD line commands/batch files... so basically all batch files need to run as administrator, use runas...

e.g. runas /user:REQUIREDUSERNAME /savecred c:\MountDrive.BAT

or create a shortcut to the batch file, then Drag&Drop it into the STARTUP folder (found under the START MENU), then right-click the icon and select the SHORTCUT tab (not the COMPATIBILITY tab), then click Advanced. There you will find another [b)Run as Administrator(/b) option that is just for shortcuts.

post back on your results... it also might help knowing the BATCH file's content (sans personal data of course)...


Ben
"If it works don't fix it! If it doesn't use a sledgehammer..."
How to ask a question, when posting them to a professional forum.
Only ask questions with yes/no answers if you want "yes" or "no"
 
It appears to run now, but when I go run Windows Explorer, i don't see the drive that it should of mapped.

I have on line in the file:

Net Use N:\PCNAME\foldername

 
that line would / should not work at all...

the line should read something along the lines of:

net use [x]: \\server\sharename

explaination:

[x] = the drive letter where you want the share to map to...
server = name of the server (or PC) or IP of the server (PC) where the share resides...
sharename = share name...

e.g. you have a share on your wife's PC (let's assume her PC has the IP of 192.168.0.10) named FreeLoad, and you want to map it to your PC (lets assume it has the IP 192:168:0:20) as drive N:

net use N: \\Wife'sPC\FreeLoad

or

net use N: \\192.168.0.10\FreeLoad

that should take care of the mapping then for you...



Ben
"If it works don't fix it! If it doesn't use a sledgehammer..."
How to ask a question, when posting them to a professional forum.
Only ask questions with yes/no answers if you want "yes" or "no"
 
I changed it to what you have. It says it completes successfully, but I still don't see the drive in Windows Explorer.
 
Open a Command Prompt and manually map the drive from there. Do you get a command completed successfully message? If so, enter the words NET USE by themselves. Are the results what you expect?
 
do post back on what Freestone asked...

it also may be an issue in that the network share is already mapped and is persistent...

you can try this, in your batch file precede the mapping command with a disconnect command first, thus making sure that the drive letter (and previous mapping to said drive letter) are clean and free to use...

e.g.:

net use N: /delete
net use N: \\Wife'sPC\FreeLoad





also remember, if you FORGET to map to a drive letter the share will, obviously, not show up in Explorer, but will be mapped...




Ben
"If it works don't fix it! If it doesn't use a sledgehammer..."
How to ask a question, when posting them to a professional forum.
Only ask questions with yes/no answers if you want "yes" or "no"
 
I opened up a command prompt and manually mapped to the share drive. The command completed successfully and I saw the mapped drive in windows explorer. I then typed net use N: /delete and that deleted the mapped drive. I then typed in the shortcut I have for the batch file which is in C:\ProgramData\Microsoft\Windows\Start Menu\programs\startup which I believe is where a batch file needs to be to be run and start up. It said it completed successfully and I saw the mapped drive in Windows Explorer. The real test will be when one of my kids logs in and I see if the drive was mapped for them.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top