I'm having a problem with scheduling a task in Windows 7
I m creating a task which is mapped to a bat file to execute,
here is my .bat file :
cd "C:\soft\"
Start excel "" "AD Auto Run.xlsm"
its working automaticaly and manually when the option (radio button) "Run only when the user is logged on" is selected.
but the automatic/manual RUN is not working when the option (radio button) "Run whether user logged on or not" is selected.
I resolved the issue by performing these steps:
Create the empty Desktop folders at the below path:
C:\Windows\System32\config\systemprofile\Desktop C:\Windows\SysWOW64\config\systemprofile\Desktop
Make sure user has “log on as batch job” permission.
To enable this please follow below steps:
a) Go to the Start menu.
b) Type secpol.msc. and press Enter.
c) The Local Security Policy manager opens.
d) Go to Security Settings - Local Policies - User Rights Assignment node.
e) Double click Log on as a batch job on the right side.
f) Click Add User or Group.
g) Select the user.
h) Click OK.
Create a file and save it with .cmd extension. The .cmd file should contain below cmd:
cscript.exe “<path to .vbs file>”
In the scheduler, give the path as follows:
• Program/script: filename (.cmd filename)
• Start in(optional): file path (path to .cmd file)
Check the mapped drive in your batch file, by adding a diagnostic command after you map the drive.
Assuming M: is the mapped drive:
if exist "M:\soft\AD Auto Run.xlsm" (
>>"c:\folder with write permissions\file.log" echo map ok
) else (
>>"c:\folder with write permissions\file.log" echo map FAILED
)
I made some changes and it appears to work like a charm. The issue like I previously stated that the excel is creating some issue.
I found that the excel file was not able to save the record set output when the user account is logged off.
So You have to create a folder (or two on a 64bit-windows):
(32Bit, always)
C:\Windows\System32\config\systemprofile\Desktop
(64Bit)
C:\Windows\SysWOW64\config\systemprofile\Desktop
After creation of the folder, my program is working fine.
Related
I have a batch file which in turn calls VB Script. The task of the VBScript contains a macro whose job is to login into the Oracle db, run few queries, fetch the output in Excel sheet and then it performs other functions.
The script is running fine in the scheduler when using the "Run only when user is logged in" option but it doesn't run when "Run whether user logged in or not" option is selected.
I tried all the options suggested here in previous posts but none of them worked.
I resolved the above issue by performing below steps :
Create the empty Desktop folders at the below path :
C:\Windows\System32\config\systemprofile\Desktop
C:\Windows\SysWOW64\config\systemprofile\Desktop
Make sure user has “log on as batch job” permission.
To enable this please follow below steps :
a) Go to the Start menu.
b) Type secpol.msc. and press Enter.
c) The Local Security Policy manager opens.
d) Go to Security Settings - Local Policies - User Rights Assignment node.
e) Double click Log on as a batch job on the right side.
f) Click Add User or Group.
g) Select the user.
h) Click OK.
Create a file and save it with .cmd extension. The .cmd file should contain below cmd :
cscript.exe “”
In the scheduler, give the path as follows :
• Program/script: filename (.cmd filename)
• Start in(optional): file path (path to .cmd file)
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.
Here's the situation, every time I need to do the step below after I boot my computer:
Open the cmd(admin)
copy this cmd into cmd:
C:\Windows\system32\netsh int ipv4 set glob defaultcurhoplimit=65
enter
For now, I hope to double click a file that can directly execute the command above without the step above.
Any method?
You can save it to .bat or .cmd file and run it on double-click.
Create a file with any name and extension .bat I.g. setLimit.bat. I assume you know how to create files.
Open file from above step in file editor, i.g. notepad.exe. Copy and paste line C:\Windows\system32\netsh int ipv4 set glob defaultcurhoplimit=65 into the file and press Ctrl+S to safe it. I hope it makes sense otherwise ask.
Double click on the file to execute the command.
If you need to run it under elevated privilege (i.e. admin) right click on file and choose Run as administrator option in menu.
You need a .bat file to execute the command and a shortcut to have it executed as administrator.
Creating the .bat file is trivial: use you favorite text editor (or notepad), type the command, optionnaly add a line PAUSE if you want to see eventual messages and save it to disk with a .bat extension (say c:\...\sethoplimit.bat)
Creating the shortcut is not much harder: right click on desktop, Create new..., Shortcut, and just select the newly created file
The magic comes now: right click on the newly created shortcut and click Properties, in Shortcut tab, click the Advanced button and select Execute as admin.
That's all. Each time you double click on the shortcut, Windows will start a console with elevated priviledges, eventually open the User Account Control confirmation dialog, and execute the batch file as administrator.
Here I showed you how to create the shortcut directly on the Desktop, but the same process can be used for a shortcut anywhere on a disk folder.
I have a .exe file converted from a .jar.
It is a command based application, so I have to start it with a batch script. Here is the batch script:
#echo off
cd C:\desktop\plant-text-adventure-win
start planttextadventure
pause
When I double click on the batch script, this happens: Windows could not find 'planttextadventure'. Please confirm if you have input the correct name and retry.
I don't know what is happening, I have no idea about cmd as I use Mac, but I can confirm I have an executable called planttextadventure.exe in a folder called plant-text-adventure-win.
You should test your batch file by executing it within a shell.
Simply enter within the start menu the command cmd to open up a shell. Within this black box you could now simply enter the commands from your batch script and lookout for some error message.
If you look at your script I would guess that the cd command (to change the current directory) is not correct. Maybe you should replace it with
cd %USERPROFILE%\Desktop\plant-text-adventure-win
because the desktop folder is on a default installation not directly under the root drive but within the user profile available.
Another solution to get this thing to work, is by opening the windows explorer, going to the .exe file you wish to execute and drag & drop the .exe file with a right mouse click onto the desktop.
Then a context menu appears and you select the option Create shortcut here.
Short version:
On Windows, if I select several .txt files in a File Explorer and then right click on one of the selected files and choose "Open" from the popup menu, all of the selected files will be opened, each in a separate instance of Notepad.
I want the same behavior for our files/editor: select multiple output files, right click one, select Open: -> all files are opened, each in their own instance of our editor.
I have basic click-to-open working (for a single file, double click opens the file in our editor, right click and Open does the same).
Details
We have an launcher (FuBarStudioLauncher.exe) that updates then launches our editor tool (FuBarStudio.exe), which produces resource files with a custom extension (samplefile.fbr)
If you run from the command line, you can fire up the editor, opening a particular resource:
C:\path_to_my_exe\FuBarStudio.exe" -ide samplefile.fbr
I have a windows registry entry set up so that when I double click on a *.fbr resource file, or right-click and select Open from the popup menu, the launcher runs, passing the given resource through to the editor.
The relevant registry entries:
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\.fbr]
#="FuBar.Place"
[HKEY_CLASSES_ROOT\.fbr\FuBar.Place]
[HKEY_CLASSES_ROOT\.fbr\FuBar.Place\ShellNew]
and
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\FuBar.Place]
#="FuBar Place"
[HKEY_CLASSES_ROOT\FuBar.Place\shell]
[HKEY_CLASSES_ROOT\FuBar.Place\shell\Open]
#="Open"
[HKEY_CLASSES_ROOT\FuBar.Place\shell\Open\command]
#="\"C:\\path_to_my_exe\\FuBarStudioLauncher.exe\" -ide \"%1\""
All of this works fine for single files.
If I select more than one .fbr file and then right click one of the selected files and select "Open", I will only open one instance of FuBar Studio.
I would like to open one Copy of FuBar Studio, one for each file.
So with some help I got a useful answer.
1) I read up on use of MultiSelectModel here:
https://msdn.microsoft.com/en-us/library/windows/desktop/hh127436(v=vs.85).aspx
Set my type to Document.
2) I created a batch script as an intermediary, so I could see better what was going on:
[HKEY_CLASSES_ROOT\FuBar.Place\shell\Open\command]
#="\"C:\\path_to_my_exe\\launcher.bat\" \"%1\""
Toyed around with this script, writing things to tmp files:
echo "interesting things" >> logs.txt
and using timeout to force things to pause/slow down:
timeout 10
Using "echo" and so forth I realized that whether MultiSelectModel is set to Document or Player, when I select multiple files and right click "Open", Windows is executing the business at:
HKEY_CLASSES_ROOT\FuBar.Place\shell\Open\command
once per selected file.
I could not find a way to force Windows to call the command once, passing all the files as arguments to the command.
3) By experimenting with other programs besides my own, and with the script + timeouts giving me a command shell with error spew to look at, I realized that my particular program, FuBarStudioLauncher.exe, always fails if another instance is running.
So here's what I have:
Windows is going to run one instance of <something> per input file.
<something> can't be my FuBarStudioLauncher.exe, because after one is running the next N will fail.
So I need an intermediary script that will do some kind of critical section locking:
- grab lock.
- run launcher to completion.
- release lock.
Hooray for StackOverflow:
Semaphore for CMD instances working in Parallel
Using this as input, my final product:
:lockedAppend
2>nul (
>>%~dp0launcher_script_lockfile.txt (
REM Do any amount of processing within this block.
REM All stdout will safely be appended to the queue
REM You could even call out to a subroutine, or another batch file
%~dp0FuBarStudioLauncher.exe -ide "%1"
REM The CALL below ensures that the block exits with ERRORLEVEL 0 - success
(call )
)
) || goto :lockedAppend
That did it!