On Windows 10.
Steps to reproduce problem.
1) Use subst from command line to setup a drive letter. e.g.: subst v: c:\temp
2) Create a batch file c:\temp\hello.bat:
echo hello
pause
3) in windows explorer, go to v: drive.
Try to run hello.bat by right clicking, and selecting Run As Administrator.
The expected Windows security question "Do you want to allow this app to make changes to your device?" comes up. When you answer Yes, nothing seems to happen.
I know I can go to c:\temp in Windows Explorer, and this will work, but it's not ideal.
I gather it is something to do with Run As Administrator context not being able to see the subst drive?
Are there any workarounds, to be able to get this to work? So that batch files can be run in Windows Explorer on the subst drive as Administrator.
EDIT:
A workaround of sorts:
In Windows Explorer, go to c: drive. Then c:\temp. Create a shortcut to hello.bat. Also tick the Run as Administrator option.
In Windows Explorer, go back to v: drive. Double click the shortcut to run hello.bat as administrator. This seems to work.
Mods: feel free to move this question to Superuser, if it turns out there is nothing you can do in the batch file itself to make this work.
Related
i have a certain program that i want to run as windows boots up
but! i need it to be only after windows restart not log off and log on are out of the question - the system i have is running tests and and the app that i want to run is canceling those tests that`s why i need it to run only after windows restarts , so there is no chance that a tests would fail because of it
the .bat file points to the location of
tried shell:common startup but that open the .bat file even after i log off or log on
how do i do this ? i need this to be in a script/.bat file as well
You should add it here
C:\Users\<user name>\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup
But cause you mentioned after only restart then you will need to run an background script to handle that restart
Or we may..
The common command to restart windows via .bat or cmd file is shutdown -r
So we can create
reboot.bat ,script.bat ,mover.bat > for example in 'C:\test' directory
reboot.bat
move script.bat "C:\Users\<user name>\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\script.bat"
shutdown -r
script.bat
: : stuff here..
C:\test\mover.bat
mover.bat
move "C:\Users\<user name>\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\script.bat" script.bat
now that we have our scripts let's add them to our Environment variables
From the desktop, right click the Computer icon.
Choose Properties from the context menu.
Click the Advanced system settings link.
Click Environment Variables.
In the section System Variables, find the PATH environment variable
and select it.
Click Edit then add ; following by C:\test Click Ok, Ok etc and
restart your cmd if opened
To answer your question just type reboot.bat or reboot in CMD command-line
Which when you want to run your script after restart you have to type this to cmd or just..make a restart.bat file with this command for just one click
I used stack overflow for android to answer this without test cause i'm not windows but i'm just familiar with plus didn't have my PC at this moment but i hope that answer is clear and understandable
Basically, I'm wondering if it's possible to sync OneDrive with a batch file. See, I can sync it whenever I go to File Explorer, right click on "OneDrive" on the left, and click "Sync," but I'm wondering if there's command windows has incorporated to have this exact same effect when used with a batch file. I have no idea what it is and have searched to no avail, so I hope that you can help me! Whatever it takes, I'm sure it would be an extremely simple script; the problem is finding out what command to use. Here's an example as a picture:
To shutdown OneDrive from the command line or in a batch file:
%LOCALAPPDATA%\Microsoft\OneDrive\OneDrive.exe /shutdown
To start OneDrive from the command line:
%LOCALAPPDATA%\Microsoft\OneDrive\OneDrive.exe /background
If the /background switch is omitted then Explorer is opened to the OneDrive folder in your user profile but OneDrive does not start.
If restarting OneDrive from a batch file then add the START command or the batch file won't end:
start %LOCALAPPDATA%\Microsoft\OneDrive\OneDrive.exe /background
Get my oneDriveSync.bat and test it.Be minded that it will work only if machine language is English.THe Sync is always the third verb but if it is inactive the third will be Pause so I cant create language independent version at the moment.
This is one simple solution:
Change OneDrive Settings to NOT Start automatically when Windows starts
Create a BAT file and launch OneDrive with Windows Task Scheduler during non-peak hours.
Create a .BAT file to Taskkill OneDrive.exe at the end of the Peak-hours:
Windows 10:
Command line to launch OneDrive (and automatically start syncing the folders/files in settings)
C:\Users\user\AppData\Local\Microsoft\OneDrive\OneDrive.exe
Command line to Taskkill Onedrive.exe
Taskkill /IM OneDrive.exe /F
A client has a nas box (nas01) and a batch script to connect three drives to it at startup.
net use h: \\nas01\home\Foo /user:Foo bar
net use m: \\nas01\music /user:Foo bar
net use p: \\nas01\media /user:Foo bar
From windows Explorer clicking on M and H drive gets him into the folders. P drive fails with a cross through it.
I opened a command prompt (cmd) as administrator (right click run as administrator) and ran the batch.
It succeeded under CMD.
It failed to let the user in under Windows Explorer.
I used net use * /delete from the CMD prompt then ran the following line manually.
net use p: \\nas01\media /user:Foo bar
In cmd I can do a dir p: and see the files, I can change to p: drive, change folders and see sub folders and files. From Windows Explorer it get Nada.
A manual disconnect for each drive then re map of drives under windows explorer fixed the issue - all four drives accessible, but it leaves me with a batch file my client cant use when Windows drops the mapped drives again in the future.
Why is one side of windows (CMD) working but not useable under Windows Explorer? Any thoughts.
User has full admin rights on PC, local login, no UAC getting in the way.
I have created a shortcut for my program (under Windows 7), whose target is in a sub-directory. But when I zip everything and send it to my colleague, the shortcut wont work because it the target directory cannot be found, it is like:
Target: C:\Users\my_user_name\Desktop\my_program\sub_directory\my_program.exe
and the shortcut is in C:\Users\my_user_name\Desktop\my_program\
When I send it to another PC, my_user_name directory cannot be found and shortcut doesnt work. How to solve this?
Create a batch file that launches the program. You can then use a relative path.
e.g.
C:\Users\my_user_name\Desktop\my_program\launch.cmd
cd sub_directory
start my_program.exe
possible solutions:
place the program with the exe on disk like c:\program\programname\ Location must be the same on all computers.
place the program with the exe on the network where you can both access, shortcut is the same
edit the shortcut in notepad and change the user
some bat files need to be launched at the start of the session, but they don't.
Actually, when trying to launch one from the explorer, it opens the Open with window instead of just runnig.
However, the bat files still run correctly from the command prompt.
I bet it has been caused by a virus, but the antivirus did not detect anything unfortunately.
Any idea?
Use the Open With command, select cmd.exe, then before you hit OK, check the box that says "always use this program to open this type of file" or something similar.
If cmd.exe is not in the choices, browse to c:\windows\system32, and cmd.exe should be in there.
You can re associate the extension by downloading the reg file for batch from the link below which should solve your problem.
http://www.dougknox.com/xp/file_assoc.htm