Run (On Command) a batch file with admin privileges and now UAC

Page 2 of 3 FirstFirst 123 LastLast

  1. Posts : 68
    Windows 10
    Thread Starter
       #11

    My batch file:


    @echo off
    taskkill /IM program1.exe /T /F
    taskkill /IM program2.exe /T /F
    pause
    exit
      My Computer


  2. Posts : 16,958
    Windows 10 Home x64 Version 22H2 Build 19045.4170
       #12

    It seems to me that the Task scheduler element of this job is the one that is causing the difficulties so, if it still causing problems, screenshots of the Task scheduler Properties dialogs for the task would help us to help you.

    On the subject of your batch file:-
    - if you are still fault finding then leave out the @echo off so you can see the responses to your commands
    - the exit command is not needed. It will exit after its last command anyway.

    Denis
      My Computer


  3. Posts : 68
    Windows 10
    Thread Starter
       #13

    So I figured out how to do this using "pskill" form PSTools, but another issue cropped up. I add PSTools to the environment variables paths, and, when I click on the batch file manually, it works as intended using the command:

    pskill -t "PROGRAM"

    But... I am running this from a hotkey through another program. It doesn't work when I do that. Instead, I get an error indicating that "pskill is not a recognized local function", or something along those lines. Basically the same error you would get if pskill was not included environment paths.

    I also notice that the working directory, when I run it through the hotkey, is different. Instead of being the directory where the batch file is saved, it is C:\Windows\System32. What gives? I have even tried changing the directory to C:\Windows\System32\PSTools, but the CD command doesn't even work when I run it through the hotkey. Is there a way to run pskill with the full directory path? i.e. something like...

    C:\Windows\System32\PSTools\pskill.exe -t "PROGRAM"
      My Computer


  4. Posts : 2,800
    Windows 7 Pro
       #14

    Simply Install PSKill in your System32 directory. I always copy all the utilities I want handy right there, for years. And it served me well.
      My Computers


  5. Posts : 46
    windows 10 19H1 winreduced
       #15

    Hi SSShadii
    Try Advancedrun
    icy
      My Computer


  6. Posts : 68
    Windows 10
    Thread Starter
       #16

    MaloK said:
    Simply Install PSKill in your System32 directory. I always copy all the utilities I want handy right there, for years. And it served me well.
    I tried this and it still doesn't recognize it. Do you have to copy all the PSTools files there or just the command you want?
      My Computer


  7. Posts : 2,800
    Windows 7 Pro
       #17

    Strange, I just copied the pskill.exe and did a test, it worked as expected.

    Run (On Command) a batch file with admin privileges and now UAC-screenshot00236.jpg
      My Computers


  8. Posts : 68
    Windows 10
    Thread Starter
       #18

    MaloK said:
    Strange, I just copied the pskill.exe and did a test, it worked as expected.

    Run (On Command) a batch file with admin privileges and now UAC-screenshot00236.jpg
    Right, it does work when I open cmd.exe or click on the Batch file and run it like that. It doesn't work when I use the hotkey program to run the batch file. I plan to go to the dev to ask why it would behave differently, but I would like to understand what is going on first.

    Is there a way of running a batch file with limited capabilities? I'll post screen shots in a minute to show what I mean.

    - - - Updated - - -

    Here is what's going on. I have a batch file that runs another batch file. Batch file 1:

    Code:
    start "" "C:\Location to bat file\batch.bat"
    Batch file 2 (batch.bat):

    Code:
    pskill
    pause
    When I click on "batch file 1", I get this from "batch file 2":

    Run (On Command) a batch file with admin privileges and now UAC-image.png

    When I program my hotkey program to run "batch file 1" on a key press, I get this from "batch file 2":

    Run (On Command) a batch file with admin privileges and now UAC-image.png

    Obviously, the hotkey program is not running CMD.exe in the same way that Windows does. Not sure why, maybe the devs built in a paired down version when compiling the program? If it was run the same way, though, I should get the same results. Since I am running a batch file to run another batch file, can't I tell "batch file 1" to explicitly run "batch file 2" in the same way that Windows would do it. Something like:

    Code:
    C:\Windows\System32\cmd.exe " start "" "C:\Location to bat file\batch.bat" "
    Last edited by SSShadii; 26 Feb 2022 at 19:22.
      My Computer


  9. Posts : 16,958
    Windows 10 Home x64 Version 22H2 Build 19045.4170
       #19

    Add to the start of your batch file 2, the line
    Code:
    CD /D "L:\Console games\hotkey"
    so that it changes drive & folder to what you want.

    Denis
      My Computer


  10. Posts : 68
    Windows 10
    Thread Starter
       #20

    Try3 said:
    Add to the start of your batch file 2, the line
    Code:
    CD /D "L:\Console games\hotkey"
    so that it changes drive & folder to what you want.

    Denis
    It changes the directory, but it doesn't find "pskill". It is like the environment path parameters are not loaded. Is there a way to manually import pskill within the batch file? i.e...
    Code:
    import C:\Windows\System32\PSTools\pskill.exe
    Run (On Command) a batch file with admin privileges and now UAC-image.png
      My Computer


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 10 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 09:19.
Find Us




Windows 10 Forums