Page 1 of 2
Bat file to create another bat file.
Posted: 25 Dec 2019 00:27
by Docfxit
Why doesn't this create a bat file for me in the same folder I run this from?
Code: Select all
@Echo Off
@echo (
If not exist "C:\Dnload\9xAddons\Macrium" md "C:\Dnload\9xAddons\Macrium"
cd "C:\Dnload\9xAddons\Macrium"
copy from //%computername%/ReflectDLHF.exe
copy from //%computername%/UpdateMacrium.exe
Call UpdateMacrium.exe
) > %~dp0UpdateMacriumRun.bat
Thanks,
Docfxit
Re: Bat file to create another bat file.
Posted: 25 Dec 2019 04:31
by bakemonogatari
try :
Code: Select all
@Echo Off
(
echo @echo off
echo If not exist "C:\Dnload\9xAddons\Macrium" md "C:\Dnload\9xAddons\Macrium"
echo cd "C:\Dnload\9xAddons\Macrium"
echo copy from //%computername%/ReflectDLHF.exe
echo copy from //%computername%/UpdateMacrium.exe
echo Call UpdateMacrium.exe
)>"%~dp0UpdateMacriumRun.bat"
Re: Bat file to create another bat file.
Posted: 25 Dec 2019 12:00
by Docfxit
That's great. That solved the problem to write out the text file.
Re: Bat file to create another bat file.
Posted: 25 Dec 2019 19:30
by Docfxit
Why am I getting "Invalid drive specification"?
Code: Select all
C:\Dnload\9xAddons\Macrium>xcopy /y /f "\\192.168.168.7\9xAddons\Macrium\ReflectDLHF.exe"
Invalid drive specification
0 File(s) copied
C:\Dnload\9xAddons\Macrium>xcopy /y /f "\\192.168.168.7\9xAddons\Macrium\UpdateMacrium.exe"
Invalid drive specification
0 File(s) copied
C:\Dnload\9xAddons\Macrium>xcopy /y /f "\\DOCFXITLT\9xAddons\Macrium\ReflectDLHF.exe"
Invalid drive specification
0 File(s) copied
C:\Dnload\9xAddons\Macrium>xcopy /y /f "\\DOCFXITLT\9xAddons\Macrium\UpdateMacrium.exe"
Invalid drive specification
0 File(s) copied
On the \\DOCFXITLT Computer the files are in:
C:\Dnload\9xAddons\Macrium\ReflectDLHF.exe
C:\Dnload\9xAddons\Macrium\UpdateMacrium.exe
I have a share setup on\\ DOCFXITLT:
C:\Dnload
This bat file is called from another PC with this:
c:\batch\psexec.exe @"C:\Batch\PushFileAndRunItComputerList.txt" -u User -p password -i -c -v cmd.exe /c start "C:\Dnload\9xAddons\Macrium\UpdateMacriumRun.bat"
Re: Bat file to create another bat file.
Posted: 26 Dec 2019 04:12
by Meerkat
Mount the network drive first like this: (you can change X: to any unused drive letter)
Code: Select all
net use X: "\\192.168.168.7\9xAddons"
Then copy files to/from the drive letter:
Code: Select all
xcopy /y /f "X:\Macrium\ReflectDLHF.exe"
After copying, unmount the network drive using this:
Meerkat
Re: Bat file to create another bat file.
Posted: 26 Dec 2019 11:29
by Docfxit
I'm using this to run the batch file from a different PC on the network:
Code: Select all
c:\batch\psexec.exe @"C:\Batch\PushFileAndRunItComputerList.txt" -s -i -c -v "C:\Dnload\9xAddons\Macrium\UpdateMacriumRun.bat"
This is the code I am running:
Code: Select all
@Echo On
If not exist "C:\Dnload\9xAddons\Macrium" md "C:\Dnload\9xAddons\Macrium"
cd "C:\Dnload\9xAddons\Macrium"
net use X: "\\192.168.168.7\9xAddons" 2>%~f0.log
xcopy /y /f "X:\Macrium\ReflectDLHF.exe" 2>%~f0.log
xcopy /y /f "X:\Macrium\UpdateMacrium.exe" 2>%~f0.log
net use X: /delete
if "0"=="0" (
echo Task Found
taskkill /f /im UpdateMacrium.exe
)
if "0"=="0" (
echo Task Found
taskkill /f /im ReflectDLHF.exe
)
Call UpdateMacrium.exe
This is what I am getting in the .log file:
Thanks for the input.
It's not mapping the drive.
Re: Bat file to create another bat file.
Posted: 26 Dec 2019 14:26
by bakemonogatari
you dont need to map a drive, check your UNC path \\ServerName(or IP)\ShareName and if the user that is used with PsExec.exe has the rights on the share.
Re: Bat file to create another bat file.
Posted: 26 Dec 2019 15:09
by Docfxit
When I try:
Code: Select all
@Echo On
If not exist "C:\Dnload\9xAddons\Macrium" md "C:\Dnload\9xAddons\Macrium"
cd "C:\Dnload\9xAddons\Macrium"
xcopy /y /f "\\192.168.168.7\9xAddons\Macrium\ReflectDLHF.exe" 2>%~f0.log
xcopy /y /f "\\192.168.168.7\9xAddons\Macrium\UpdateMacrium.exe" 2>%~f0.log
if "0"=="0" (
echo Task Found
taskkill /f /im UpdateMacrium.exe
)
if "0"=="0" (
echo Task Found
taskkill /f /im ReflectDLHF.exe
)
Call UpdateMacrium.exe
I get in the .log file:
Re: Bat file to create another bat file.
Posted: 26 Dec 2019 15:42
by bakemonogatari
launch cmd, type :
Code: Select all
pushd \\ServerName(or IP)\ShareName
echo %cd%
dir
pause
popd
what is displayed?
Re: Bat file to create another bat file.
Posted: 26 Dec 2019 17:26
by Docfxit
Thanks for the reply...
pushd \\ServerName(or IP)\ShareName
Code: Select all
The specified network password is not correct.
echo %cd%
dir
Code: Select all
Volume in drive C is Windows7_OS
Volume Serial Number is 8149-5200
Directory of C:\Windows\system32
12/20/2019 05:45 PM <DIR> .
12/20/2019 05:45 PM <DIR> ..
07/13/2009 08:56 PM <DIR> 0409
06/10/2009 01:16 PM 2,151 12520437.cpx
06/10/2009 01:16 PM 2,233 12520850.cpx
10/07/2007 10:27 AM 10,752 aamd532.dll
09/24/2009 09:40 AM 516,216 accesor.dll
11/20/2010 04:18 AM 3,727,872 accessibilitycpl.dll
07/13/2009 05:03 PM 39,424 ACCTRES.dll
07/13/2009 05:14 PM 7,680 acledit.dll
07/13/2009 05:14 PM 125,440 aclui.dll
09/09/2019 04:10 PM 257,024 acmigration.dll
11/20/2010 04:18 AM 45,568 acppage.dll
07/13/2009 05:14 PM 9,216 acproxy.dll
11/20/2010 04:18 AM 744,448 ActionCenter.dll
11/20/2010 04:18 AM 537,600 ActionCenterCPL.dll
11/20/2010 04:18 AM 179,200 ActionQueue.dll
11/20/2010 04:18 AM 202,752 activeds.dll
07/13/2009 03:37 PM 111,616 activeds.tlb
11/20/2010 04:18 AM 309,760 actxprxy.dll
07/13/2009 05:14 PM 38,912 AdapterTroubleshooter.exe
<Cut Too many characters for this post>
3185 File(s) 1,563,928,095 bytes
96 Dir(s) 15,969,931,264 bytes free
pause
popd
Docfxit
Re: Bat file to create another bat file.
Posted: 26 Dec 2019 18:19
by bakemonogatari
it seems you have a "problem" with the account you use to launch cmd... (or) also, you need to be sure you are first targeting \\Server\Share and not \\Server\Share\Subfolders.
ideally, you need an account which already has rights on sharing (and which is a local administrator on PCs ...)
Don't you have an (Domain) administrator account? if yes, launch cmd as administrator (of the domain), then pushd etc.
Also, i'm not sure what you're trying to do is possible the way you're trying to do it, because of the "-s" that will be used with psexec to launch your script on the remote system (you need an account which have rights on your \\server\share to copy files).
Re: Bat file to create another bat file.
Posted: 26 Dec 2019 22:10
by Docfxit
On the computer I'm running this bat file on, there is a user "User1" with "Password1" and administrative rights.
I am not logged in with "User1" but "User1" is defined.
Running in Win7 Professional 32bit
With "Enable NETBIOS over TCP" checked
I do have a user "Administrator" active with "Password2" with Administrator rights.
On the computer "192.168.168.7" there is the same user "User1" with "Password1" and administrative rights.
There is a share setup for C:\Dnload for "User1" with read/write
I am logged in with "User1"
Running in Win7 Ultimate 32bit
With "Enable NETBIOS over TCP" checked
I do have a user "Administrator" active with "Password2" with Administrator rights.
What am I missing?
Thanks,
Docfxit
Re: Bat file to create another bat file.
Posted: 27 Dec 2019 07:01
by bakemonogatari
on your computer, connect with User1, launch the file explorer, in the address bar type \\192.168.168.7
are you asked for a username and password ?
does a 9xAddons share exist?
are you asked for a username and password when accessing to that share ?
check if the full path \\server\share\etc. matches what you thought
if there's a problem, make it simple, try to share to everybody with only read rights (also, check security tab), log off \ log on with User1, does it works now ?
Re: Bat file to create another bat file.
Posted: 27 Dec 2019 09:30
by Docfxit
bakemonogatari wrote: ↑27 Dec 2019 07:01
on your computer, connect with User1, launch the file explorer, in the address bar type \\192.168.168.7
are you asked for a username and password ?
Yes. I don't understand why because I have the same user on both machines.
I did enter the user/password and I did put a check in remember.
No. Only Dnload
bakemonogatari wrote: ↑27 Dec 2019 07:01
are you asked for a username and password when accessing to that share ?
No.
bakemonogatari wrote: ↑27 Dec 2019 07:01
check if the full path \\server\share\etc. matches what you thought
I had been running it like this:
xcopy /y /f "\\192.168.168.7\9xAddons\Macrium\ReflectDLHF.exe" 2>%~f0.log
I found I needed to run it like this:
xcopy /y /f "\\192.168.168.7\dnload\9xAddons\Macrium\ReflectDLHF.exe" 2>%~f0.log
bakemonogatari wrote: ↑27 Dec 2019 07:01
if there's a problem, make it simple, try to share to everybody with only read rights (also, check security tab), log off \ log on with User1, does it works now ?
Thanks to you, I figured it out. That's really great of you to spend the time to help me get this working.
Thanks,
Docfxit
Re: Bat file to create another bat file.
Posted: 27 Dec 2019 10:16
by Docfxit
I seem to be having a terrible time trying to get Psexec to work correctly.
I am running this from a user with administrator rights and I am running this as administrator.
this is my complete script:
Code: Select all
@Echo On
for /f "delims=[] tokens=2" %%a in ('ping -4 -n 1 %ComputerName% ^| findstr [') do set NetworkIP=%%a
(
echo: @Echo On
echo: If not exist "C:\Dnload\9xAddons\Macrium" md "C:\Dnload\9xAddons\Macrium"
echo: cd "C:\Dnload\9xAddons\Macrium"
echo: xcopy /y /f "\\%NetworkIP%\Dnload\9xAddons\Macrium\ReflectDLHF.exe"
echo: xcopy /y /f "\\%NetworkIP%\Dnload\9xAddons\Macrium\UpdateMacrium.exe"
Echo: tasklist /fi "imagename eq UpdateMacrium.exe" 2>NUL | find /I /N "no tasks are running">NUL
Echo: if "%errorlevel%"=="0" ^(
Echo: echo Task Found
Echo: taskkill /f /im UpdateMacrium.exe
Echo: ^)
Echo: tasklist /fi "imagename eq ReflectDLHF.exe" 2>NUL | find /I /N "no tasks are running">NUL
Echo: if "%errorlevel%"=="0" ^(
Echo: echo Task Found
Echo: taskkill /f /im ReflectDLHF.exe
Echo: ^)
Echo: Call UpdateMacrium.exe
) > %~dp0UpdateMacriumRun.bat
c:\batch\psexec.exe @"C:\Batch\PushFileAndRunItComputerList.txt" -u MyUser -p MyPassword -i -c -v "C:\Dnload\9xAddons\Macrium\UpdateMacriumRun.bat"
This bat file creates another bat file with the correct IP address of the PC I run the bat file from.
Then Psexec sends the bat file that was created UpdateMacriumRun.bat to another PC on my LAN.
On the other PC a cmd window comes up with a cmd prompt. The files do get copied. I expect the Call UpdateMacrium.exe to run.
If I run this bat file on the target PC, it runs fine.
I figured out the problem. I needed to add the -i to the Psexec cmd line.
It's running now.
Thanks,
Docfxit