i am trying to use this command in cmd
runas /user:Mymachine\kanhaji diskpart
but it say
RUNAS ERROR : unable to run -diskpart
740 : the requested operation requires elevation.
this is the only user on my system
and it is already an administrator
although going to C:/windows/System32/diskpart.exe -> right click -> run as administrator
works fine
but i just want it to do with cmd
i am creating a batch file which will simply hide my disks on all my systems after just running this batch files
#echo off
runas /user:Mymachine\Kanhaji diskpart
mypassword
select volume 3
remove letter f
i am going to access this batch file through telnet so i have to run it as administrator through command only
Firstly you need to disable UAC I am not sure which Windows version you are using, but here is a good start
Then running diskpart in a script might be simpler if you using it with the script option. so once UAC has been disabled, you can create a .cmd file and a script file.
the script file will contain your actual diskpart commands to perform for instance:
Create a Script file which we will call myDiskScript.txt with the content:
select disk 4
format quick fs=ntfs label="My Disk"
Then create a batch file called MyDiskBatch.cmd and insert the commands. i.e
diskpart /s f:\myDiskScript.txt
Ensure that you point the full path of the myDiskScript.txt in the batch file, else it will search for the script in the execution directory.
You can then run the file via scheduler or by manually execution.
The nice thing about this is that you can create a batch file that does some checks and create the myDiskScript.txt file based on the result of your initial tests, then execute it, making it fairly dynamic then.
I have a batch file stored on my work network. When i go manually on the target folder and open my batch file it works just fine.
Thus I wanted to put this command in my task scheduler, went on it and for its action, browsed my file, got a path Y:\ and such
However when i launch my scheduled task, i have a pop up saying windows doesn't find my bat file and my cmd writes "the path can not be found"
I believe that is because with cmd it starts naturally on the C disk, thus as it is not on the right disk, the path is not found.
A pushd to change disk from C to Y works afterwards, however i have to do that manually on cmd
My question is, how can i handle my task scheduler to launch my file without having to create a copy of my file on the local disk? I would really like it to launch the bat file stored on work network.
Thought at first to write on my bat file the pushd line but well, the file is still stored on the network haha..
Thanks for your help
Run a local batch file to map the network drive as Y
net use y: \\server\blah
Then have it call your network batch file at Y:
call y:\mybatch.bat
As task scheduler runs normally as a different user it doesn't have your drive mappings.
Alternatively call the batch file via it's unc path \\server\blah\mybatch.bat and then on the first line of the batch file pushd the unc path again
pushd \\server\blah\
I'm trying to make a scheduled task that runs a python script in a particular directory located on a network drive. I figured I need a batch file in order to achieve this.
I'm running the following in command prompt successfully:
pushd \\mydrive\somedirectory
Z:\>
But I'm trying to do the same thing in a batch file and get:
The network name cannot be found,
The system cannot find the path specified.
What might I be doing incorrectly?
Run a batch file from Task Scheduler is not working with a java command inside the .bat file. If I run the .bat file manually its working good.
Here is the simple .bat file I'm trying to schedule
set JAVA_HOME=C:\Program Files (x86)\Java\jdk1.6.0_24;
set CMD= "%JAVA_HOME%\bin\java" -version
echo %CMD%
%CMD%
When you type batchfile.bat on the command line, you are telling cmd.exe to read the file and execute each line it finds in it. When you double-click on your batch file in explorer, it calls cmd.exe for you, after reading the file associations in the registry.
Task Manager is not so kind.
So for your task to work, schedule it like this (from memory, not on a Windows box right now) :
cmd /c "c:\full\path\to\your\batchfile.bat"
For extra robustness, you could make sure you batch file run from a known directory, like the one that it reside in, by adding this at the top:
pushd %~dp0
REM .... The original batch file goes here ....
popd
And finally you could disable CMD autorun entry by adding /d right after cmd like this:
cmd /d /c "c:\full\path\to\your\batchfile.bat"
If ixe013's suggestion doesnt work go to
'Actions'
'Edit' the task
'Start in (optional):' Put the path to the directory where the script is
So for the last one if you have 'C:\Users\Desktop\script.py' just put in 'C:\Users\Desktop\' in the 'Start in (optional):' field
What worked for me was running the task as "Users" ( computername\Users ). Once I did that, and "run with highest privileges" checked, it ran without a hitch.
Giving the full path of java.exe in the batch file fixed it for me. In a notepad, I typed the following line:
"C:\Program Files\Java\jdk1.8.0_40\bin\java.exe" -jar "C:\Users\usernameXXXX\Documents\NetBeansProjects\JavaApplication5\dist\JavaApplication5.jar"
Save this as a app1.bat file (C:\temp\app1.bat)
In the Actions tab of the task scheduler, give the path to the batch file, i.e, C:\temp\app1.bat
Also, be careful in the Conditions tab of task scheduler- make sure you uncheck "Start the task only if the computer is on AC power"
All other ways did not work for me, I followed this guide:
http://richardstk.com/2012/06/15/scheduled-task-to-run-a-batch-file/#comment-6873
In order to get the batch file to run, I had to set the "Program\script" box to contain just the name of the script (ie. script.bat) and set the the folder path of the script in the "Start in (optional)" box
I gave full permission to user Everyone from security tab from Properties of the folder in which batch file is. and it started working.
What a coworker discovered on something he had that wasn't working, and I have verified on the system I had that wasn't working is the following:
When the whole task is initially setup, you HAVE TO initially use the radio button "Run only when user is logged on". It will ask for your password for the change.
Now run the task.
Verify that whatever the batch was supposed to do, did happen.
And THEN change to the radio button BACK TO 'Run whether user is logged on or not."
This solved a problem for both of us that we had individually been working on for hours.
Side notes: both issues were also trying to elicit a 3rd party FTP app (WinSCP and WinFTP respectively) in each of our cases. Regular "inhouse" batch/tasks were having no issues.
I had the same problem, and to solve it, I put the next command line into the batch file:
cd "CURRENT_DIRECTORY"
where CURRENT_DIRECTORY is the directory where the batch file is located.
Example:
Suppose i have my batch file named test.bat located into c:\windows\system32\mytest
in my test.bat file, i introduce the next command line:
cd c:\windows\system32\mytest
I have a batch file that part of it copies a folder and its content to a local directory and then continues through the batch process which then tries to execute the contents of the folder . locally run it works on all wintel os and copies the files from \networkshare\folder*.* to %systemdrive%\temp\ .
I have attempted to use e.g psexec #serverlist.txt -c batfile.bat -s -f -d to copy the file and then execute it remotely how ever the issue is that this will not copy the files when run remotely . I think its a authentication issues after you a have remotely executed the batch file the remote system will not allow me to access/authenticate the networkshare
i have tried xcopy , copy , robocopy .
AFAIK you can only authenticate against the next hop using implicit credentials. Connection attempts from the first hop to a second hop will fail, even if your user has the required permisssions. See e.g. here for an explanation.
Try this:
psexec #serverlist.txt -u %USERDOMAIN%\%USERNAME% -d -c batfile.bat
Use explicit credentials so you're authenticated against the remote host. With that the second hop will be the next hop for your authenticated session. Don't run the script as LOCAL SYSTEM (-s), because that account is restricted to local resources.
I've had this issue in the past. Instead of trying to copy/run the BAT file just run the script things from a UNC path if you are able to. I think the problem lies in the BAT file not actually able to run through PSEXEC and copy like you think. Does it give an exit code?
Here's an example I used a while ago to install Adobe reader. I tried to do it through a batch file but no dice. I could not get it to run within the batch file whether I copied it or not. I can't remember the exact reason, I think it had something with the way a batch file is called in the system and runs in some sort of local context. Don't quote me on that though as I can't remember the exact why.
Here is my code example:
psexec /accepteula \\%computer% -s cmd /c msiexec /i "\\UNC\Software\adobe\Adobe Reader 7.0.9.msi" TRANSFORMS="acrobat7.mst" /qn