Defining a variable by user input for creating folder PSExec

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
HCV242
Posts: 4
Joined: 28 Jan 2010 05:21

Defining a variable by user input for creating folder PSExec

#1 Post by HCV242 » 28 Jan 2010 06:05

Defining a variable by user input for creating a folder with the command MD

The batch ive done works locally, but if execute it remotely with PSexec it doesnt work


I'm using:

@ECHO OFF
SET /P user= USERNAME:
md %user%
cd %user%


If i run it remotely the folder created will only have the first letter of the %user% variable.
ive tried using SETLOCAL with no luck. :/

any guesses ?
thanks

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Defining a variable by user input for creating folder PSExec

#2 Post by aGerman » 28 Jan 2010 06:21

Hi HCV242,

mabe you've got a problem with blanks. Have you ever tried to use double quotes, like

Code: Select all

@ECHO OFF
SET /P "user= USERNAME: "
md "%user%"
cd "%user%"


Regards
aGerman

HCV242
Posts: 4
Joined: 28 Jan 2010 05:21

Re: Defining a variable by user input for creating folder PSExec

#3 Post by HCV242 » 28 Jan 2010 07:38

Hi HCV242,

mabe you've got a problem with blanks. Have you ever tried to use double quotes, like

Code:
@ECHO OFF
SET /P "user= USERNAME: "
md "%user%"
cd "%user%"



Regards
aGerman



Hi aGerman, thanks you for trying to help.

adding "" doesnt solve my problem. with the "" the folder is created correctly locally as before but ( cd "%user%" ) isnt executed.

if i execute it remotely via Psexec cmd the folder isnt created, as before of adding the ""

anymore guesses ?

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Defining a variable by user input for creating folder PSExec

#4 Post by aGerman » 28 Jan 2010 08:12

[...] but ( cd "%user%" ) isnt executed.[...]


Hi HCV242.
Why not? :shock: Can't believe. Worked nicely for me. What kind of special characters are probably used for the username?

At home I will check it using PSexec.

Regards
aGerman

HCV242
Posts: 4
Joined: 28 Jan 2010 05:21

Re: Defining a variable by user input for creating folder PSExec

#5 Post by HCV242 » 28 Jan 2010 08:49

No special characters are used... but if i dont use the "" it executes the (CD).


But before that it doesnt create the folder with the username correctly. but only if i run it remotely on another machine. locally it creates it correctly.

ie: remotely i enter SUE as username and it creates a folder named S ...it only takes the first letter.
if i run it locally it creates the SUE folder correclty.

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Defining a variable by user input for creating folder PSExec

#6 Post by aGerman » 28 Jan 2010 09:23

Localy once again. I created this batchfile on my desktop.

Code: Select all

@ECHO OFF
SET /P "user= USERNAME: "
md "%user%"
cd "%user%"
:: show where we are:
echo %cd%
pause

returns:
USERNAME: SUE
C:\Documents and Settings\[***]\Desktop\SUE
Press any key to continue . . .


Will try with PSexec in the evening.

Regards
aGerman

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Defining a variable by user input for creating folder PSExec

#7 Post by aGerman » 28 Jan 2010 15:58

Hi again,
I tried it using PSexec.
Say I have a Batchfile on my local PC with the following contents

Code: Select all

@echo off
psexec \\remotepc -w C:\data C:\data\abc.bat
pause

and a "C:\data\abc.bat" on the remote computer contents

Code: Select all

@ECHO OFF
SET /P "user= USERNAME: "
md "%user%"
cd "%user%"
:: show where we are:
echo %cd%
pause


By starting the local *.bat the remote abc.bat will be called. For me absolutely does what it should do. The new folder has been created under C:\data and the CD command also worked fine.

Regards
aGerman

HCV242
Posts: 4
Joined: 28 Jan 2010 05:21

Re: Defining a variable by user input for creating folder PSExec

#8 Post by HCV242 » 29 Jan 2010 09:09

thanks a lot for your help, aGerman.

what im doing is a bit different;

i start a remote command line on the remote pc

psexec \\remotepc cmd

and only then i run the .bat file.
the .bat file i want to run is already on the remote pc.

but im going for your aproach...and drop mine

thanks a lot for the help again.

sxekjb
Posts: 16
Joined: 07 Nov 2009 19:13

Re: Defining a variable by user input for creating folder PSExec

#9 Post by sxekjb » 29 Jan 2010 09:54

Just my input, but I've never gotten set /p to work through a psexec remote command terminal; There's an unknown on-going keyboard input issue with it, just google "set /p psexec" and you'll see what I mean. Tks

Post Reply