log into a system

  • Thread starter Thread starter Gurur
  • Start date Start date
G

Gurur

I want to create a batch file for copying files from a system to
another.
But the problem I am facing is how to log into a system that requires
a username and a password. I am working on Windows 2000 & its on LAN.
 
You can simply map a drive which allows you to pass credentials. You can do
this with a DOS or WSH script.

-------------------
DOS Example
---------------------------------------------------------------
REM [Authenticate]
net use X: \\Server\Share /user:my_domain\user_ID user_pwd

IF NOT EXIST X:\*.* goto :ERROR_CONNECTING



The "/user:" switch of the "net use" command accepts accounts names in the
form of User Principles Names such as, user@my_domain.com, or the old
NetBIOS style names, my_domain\domain_user or server\local_user. You can
leave the password off, and you will be prompted for it when the script is
ran. An other option if you don't want the user's name and password embedded
in the script, is to have the credentials cached in Windows' "Protected
Store".



-------------------
WSH (vbScript) Example
---------------------------------------------------------------

Set oWS = WScript.CreateObject("WScript.Shell")
Set oWN = WScript.CreateObject("WScript.Network")


On Error Resume Next

Err.Clear

oWN.MapNetworkDrive "X:", "\\server\share", False, "my_domain\user_ID",
"user_pwd"

If Err.Number <> 0 Then
oWS.PopUp "Connection to one or more shares failed!", 3, "ERROR:
Authenticating", vbExclamation
Else
oWS.PopUp "All Shares mapped!", 1, "SUCCESSFUL: Authenticating",
vbInformation
End If

On Error GoTo 0
 
Harvey Colwell said:
You can simply map a drive which allows you to pass credentials. You can
do this with a DOS or WSH script.

And note that Harvey's example where "my_domain" is used to
be instead "the_server" if the user account were a server account
instead of a Domain user.

The only real problem with this is the need to hardcode the password.
 
Herb Martin said:
And note that Harvey's example where "my_domain" is used to
be instead "the_server" if the user account were a server account
instead of a Domain user.

The only real problem with this is the need to hardcode the password.

To prevent placing the user ID and password within the batch file, use the
following code segment that I borrowed from Herbert Kleebauer:

@echo off
echo hP1X500P[PZBBBfh#b##fXf-V@`$fPf]f3/f1/5++u5>"%temp%\_.com"
Set /p usr=Enter User ID:
Set /p pw=Enter Password for User ID %usr%:<nul
for /f "tokens=*" %%i in ('%temp%\_.com') do set pw=%%i
del "%temp%\_.com">nul

::::::::::::::::::::::::::::::::
::*** Do your process here ***::
::::::::::::::::::::::::::::::::

set usr=
set pw=


This way you can use the environment variables (%usr% and %pw%) thoughout
your batch file for authentication.


B_Mann
 
Back
Top