Win7 - Batch script to explore to a remote folder

Status
Not open for further replies.

JeffO

Baseband Member
Messages
50
Location
Denver
Does anyone know a way to use scripting to pass credentials to a network computer or shared folder using either simple batch script or PowerShell?

I'm an IT Tech who frequently has to browse to various network folder locations. I have batch scripts that I like to use. With XP, all I had to do was the following...
Code:
cls
IF not %userdomain%==%computername% goto explore

:user
@color 1f
@set /p useris=Type Your Username: 
@color 9f
net use \\ThatNetShare\ipc$ /user:MyDomain\%useris%
@echo.
@color 07

:explore
explorer.exe \\ThatNetShare\d$

A bit fancy for a simple task, but it works regardless of situation. Of course, the meat-and-potatoes of this are simply "explorer.exe \\ThatNetShare\d$". But Windows 7 hangs on this and then fails. Part of the new security model. I think maybe I'm out-of-luck. There might no longer be a way to do this, to thwart the hackers and virus-writers.
You can type " \\ThatNetShare\d$" into an Explorer address bar, and it will prompt you for credentials, if required, and it'll work, but that's tedious. Microsoft intentionally broke the traditional way of passing credentials - and maybe they've gotten rid of it completely?

Does anyone know a way to use scripting to pass credentials to a network computer or shared folder using either simple batch script or PowerShell, that works in Windows 7?
 
From what i know it isnt possible. Your right it was done to prevent hacking and the virus writers. Cause the old way it was far to easy to get this information. You show how easy it is without having to have the proper rights you can access and obtain all information on a network.

There is no way that i know of to use any sort of script or powershell to do what you want. Maybe part of the new GPO might have something like this, but as far as executing a single script, i doubt it.
 
I got it! Very simple.
The script above breaks when trying to map to the hidden share "ipc$", which Pre-Vista machines take. Vista and later don't take this, but you can still pass credentials to an entity. Just delete \ipc$ and it works.

So, the logic of the script goes as follows...
- Check to see if the user is logging onto a corporate network domain or just the local computer (local domain, since all computers are their own mini-domain). If logging onto the local-domain, the domain name will equal the %userdomain% variable. If the user logs onto a corporate domain, then authentication will be seemless, so skip to the last command. But if the remote network-domain computer doesn't know who you are, then continue to the next section which allows you to pass credentials to the remote PC.

- The next section prompts for your username.
- The username is sent to the remote PC, which queries locally, then AD, which automatically prompts you for your password (no asterisks will appear as you type it in, but it's working).

- Then the last command tells Windows Explorer to open a window to the D: drive of the remote PC. The ipc$ hidden share is gone, but the c$, d$, etc. hidden shares still work. Windows 7 security may not allow this command to take you all the way to the remote drive, as commanded. It may instead just take you to the root machine...
\\TheRemotePC
instead of...
\\TheRemotePC\D$
But adding it to the address field of Windows Explorer manually will get you in.

So this might not be as totally fast as with XP, but at least it isn't "broken".

One reason I prefer a script instead of a shortcut is that machines and paths change - my work environment is very dynamic. I've seen shortcuts that point to non-existent places lock-up computers when clicked on. If nothing else, they slow a computer down - maybe miliseconds, maybe seconds, but add several bad shortcuts together, and especially if they're on the Desktop, and you have everything getting slowed down. A script can't have such a deleterious effect. The script might hang if you try to run it, but the computer's general performance won't suffer from it sitting there on the Desktop, or in a folder.
 
Status
Not open for further replies.
Back
Top Bottom