Copy Random Files using particular domain username

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
amit_m04
Posts: 2
Joined: 03 Feb 2016 03:25

Copy Random Files using particular domain username

#1 Post by amit_m04 » 03 Feb 2016 03:38

Hello,

I am trying to create a script which will copy random files to a specific local/ network folder.
These files should be copied using a domain username and password.

I have created a script however it is giving me error "1783: The stub received bad data"
Below is the script.
----------------

Code: Select all

@echo off
setlocal EnableDelayedExpansion
cd "C:\Random Files\"
set dr=%cd%
set n=0
for %%f in (*.*) do (
   set /A n+=1
   set "file[!n!]=%%f"
)
set /A "rand=(n*%random%)/32768+1"
set fl1=%dr%\!file[%rand%]!
echo %fl1%

runas /env /user:contoso\Aahana.S "cmd /k copy \"%fl1%\" \\vfile1\test"

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

If i use below given command then i am able to create a file on the network share.

runas /env /user:contoso\Aahana.S "cmd /k copy \"C:\Randome Files\Code12a.txt\" \\vfile1\test


When i use same command in script it gives me "1783: The stub received bad data" error.
Request your help on this.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Copy Random Files using particular domain username

#2 Post by foxidrive » 03 Feb 2016 08:00

amit_m04 wrote:If i use below given command then i am able to create a file on the network share.

runas /env /user:contoso\Aahana.S "cmd /k copy \"C:\Randome Files\Code12a.txt\" \\vfile1\test


The quoting you show there is not the same as your code - and it looks like it wouldn't work either with unbalanced quotes.
The path is also different and it gives an indication that what you are describing as fact, isn't factual.

amit_m04
Posts: 2
Joined: 03 Feb 2016 03:25

Re: Copy Random Files using particular domain username

#3 Post by amit_m04 » 04 Feb 2016 01:10

If I execute in debug mode then in the background it uses this same line, below is the debug of the file, and still it is not creating the file and giving 1783 error.

C:\Randome Files>set /A "rand=(n*8090)/32768+1"
C:\Randome Files>set fl1=C:\Randome Files\!file[53]!
C:\Randome Files>echo C:\Randome Files\Code12a.txt
C:\Randome Files\Code12a.txt
C:\Randome Files>runas /env /user:wipvrn\Aahana.S "cmd /k copy \"C:\Randome Files\Code12a.txt\" \\vfile1\test"

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Copy Random Files using particular domain username

#4 Post by foxidrive » 04 Feb 2016 16:18

What else is on the console screen when that error appears?
It seems that the error message has more to it than that.

Which release of Windows is it?

Compo
Posts: 600
Joined: 21 Mar 2014 08:50

Re: Copy Random Files using particular domain username

#5 Post by Compo » 05 Feb 2016 04:38

Instead of using 'RunAs' have you tried using 'Net Use' to connect before copying?

Example:

Code: Select all

@Echo Off
SetLocal EnableDelayedExpansion

Set WD="C:\Randome Files"
Set NF="\\vfile1\test"

Set TF="%Temp%\_$.tmp"
Set "SW=/FP /L /NC /NDL /NJH /NJS /NS /R:0 /W:0 /XA:SH /XF *.lnk *.url /XJ"
For /F "Tokens=*" %%A In (
   'RoboCopy %WD% NULL %SW%') Do >>%TF% Echo=!Random!:%%A
For /F "Tokens=1*Delims=:" %%A In ('Sort %TF%') Do Set RF="%%~nxB"
Net Use %NF% /User:wipvrn\Aahana.S *
RoboCopy %WD% %NF% %RF% /CopyAll
Del %TF%
Net Use %NF% /Delete
Pause>Nul
You can replace the asterisk on line 12 with your password if required.

Post Reply