Any way I can start a file in a batch file when running it as administrator?

ChaoticWolf

Estimable
Feb 2, 2016
61
0
4,610
I don't know why, but if you run a batch file as administrator and it attempts to run something using the start command, it says that it can't find it, even though its in the location. Is there a work around this?
 
Solution
Then the fix was successful, because the script was found. This is another problem, most likely with your use of the "start" command. I would just execute it with WScript or CScript instead unless you really need to use start.
Sort of going out on a limb here for lack of detail....

However, whatever you are trying to start may have its startup type set as "disabled". Won't be able to start. However, my question is then why would that be reported as "can't find it"......

Are you able to post what service/process you are trying to start, your batch file, and the error message being returned?

That information could be helpful.
 

ChaoticWolf

Estimable
Feb 2, 2016
61
0
4,610


I'm trying to make it run a .vbs script file. It's in the same folder as the batch file, and whenever I run the batch file as admin and it attempts to run the file, it says it cannot find it. It runs normally with no administrator mode ran, however I require to have it run as admin for my software I'm coding. It just says like "Windows cannot find the file "file"" you know, the regular standard normal error message you would usually get if you were to attempt to have cmd or batch run something and you put the wrong destination. I did run command prompt as admin and attempted to run the vbs file with it and it worked. However it didn't work with a batch file, like so.

 

randomizer

Distinguished


By default, when you run the batch file as admin it creates a new session for the command prompt and sets the working directory to "%SystemRoot%\system32", which is typically "C:\Windows\system32". Just open a new command prompt as admin and you'll see that is the case. If you want the directory of the batch file, change the directory to "%~dp0" using either "cd %~dp0" or "pushd %~dp0" (if you want to go back and forward between directories, learn to use pushd and popd).
 

ChaoticWolf

Estimable
Feb 2, 2016
61
0
4,610


It's a batch file that will delete certain Windows Updates for me. When I delete the updates, I like to make a restore point, so the vbs script I mentioned makes one automatically for me. So when the batch file deletes the updates, before it does, it'll run the script that makes a restore point then it will delete the updates. so it just pretty much attempts to run automatically when the batch file is executed.
 
Per Randomizer's observation and comment:

Are you able to post your script? Comment each section as appropriate and be sure to indicate where the error occurs.

Where you "are", where the script "is", and where the system "is" could be three different places. And thus the file "cannot be found".

 

ChaoticWolf

Estimable
Feb 2, 2016
61
0
4,610


Script is in the same folder as the batch file. so i dont have to put any directories on the start command
It's not a problem with the script, its with any file that the batch file attempts to run. and as i already said, when i run the batch file, it automatically attempts to execute the start command and the file so its in the beginning, when i automatically get the error.


 

ChaoticWolf

Estimable
Feb 2, 2016
61
0
4,610


I tried doing the quote thing like you mentioned, but that didn't seem to work. All that did was open up Command Prompt as administrator in another window.

What I did:
start "createrestorepoint.vbs"
If that's what you meant with the quotes
i also did start "" "createrestorepoint.vbs"
returns same error message with that one.



 
How are you starting Visua Basic per se?

Can you demonstrate via your script that Visual Basic is running?


Will something like this via PowerShell work?

PS C:\> cscript c:\batch\createrestorepoint.vbs

However, the confusion is, to me at least, is the desired end objective.

Example - the following link:

http://stackoverflow.com/questions/11899730/running-vbscript-from-batch-file

Basically just more examples that you can mimic as appropriate for your full requirements.
 

ChaoticWolf

Estimable
Feb 2, 2016
61
0
4,610


PowerShell didn't work. Just got
"PS" is not recognized as an internal or external command, operable program or batch file.

i also tried using powershell instead of ps, didnt work

this is so annoying, atleast allow users to run files as administrator before publishing your os, microsoft

 
Are you running Windows 10?

How did you attempt to start PowerShell?

You should be able to type "Powershell" into the Search the web and Windows box, click the Desktop app, and select "Run as administrator".

If not Windows 10 then what OS version are you running?

EDIT: Update.

Had a few available minutes and checked on something I remembered:

You can set a restore point in PowerShell via the CheckPoint-Computer cmdlet.

And you can delete update files as well; Here is a link:

http://www.scconfigmgr.com/2014/11/18/remove-expired-and-superseded-updates-from-a-software-update-group-with-powershell/

May be going off topic a bit as I am not sure if you just need to get it done or need to use .vbs per se.

In anycase Powershell is quite potent - so much to learn. And I am not one to reinvent the wheel and will look for solutions that I can modify or otherwise tweak to my purposes. Hence the links....
 

ChaoticWolf

Estimable
Feb 2, 2016
61
0
4,610


Windows 8.1 Pro 64-bit

I just used the command that you told me to use but used PowerShell instead of PS as the beginning command

I'm aware that you can delete update files as well from windows update and other ways, but i'd prefer doing them over a batch file to save me some time, other than have to go clicking around typing in all the updates into windows update and deleting them


 

randomizer

Distinguished
You are overcomplicating this. The problem is trivial to fix. My previous post explained why you're receiving this message and included a solution (with the caveat that I'm going off the symptoms, as you haven't posted the script).
 
"Clicking around"? Not sure that I follow.....

If you set up a PowerShell script file with the necessary cmdlets then that script will do all the work.

In agreement with Randomizer's comment. And, as for myself, without the script I am not really sure about the bigger picture and the end objective(s).
 

ChaoticWolf

Estimable
Feb 2, 2016
61
0
4,610


Fine, if you really want the script (which i really think has nothing to do with the batch file having issues looking for it) then here it is, check it out: http://www.mediafire.com/download/sq2iqsu53b89u3u/createrestorepoint.vbs

 

ChaoticWolf

Estimable
Feb 2, 2016
61
0
4,610


Clicking around as in going to the start menu, typing in Windows Update, clicking on windows update, clicking on the search bar, typing in the update, click on the update, right click on the update and click delete and click ok. batch files can save you lots of time with tasks.

If you REALLY need the script, then download it, which the link is above.

This isn't the only batch file that won't read a file that i put on the start command. this isnt my computer, not my batch file, it's just something wrong with the cmd that microsoft doesnt fix, or for some apparent reason, it isnt fixable. this happens to every batch file. you run it as administrator, in whatever area the batch file attempts to run a file using the start command, says "Windows cannot find the file. Make sure you typed its name correctly, and try again"