Help with the creation of a (to me) complicated bat file


  1. Posts : 23
    Windows 10
       #1

    Help with the creation of a (to me) complicated bat file


    Hi people! I have a pretty complicated (to me) task to accomplish.

    I have a notebook with Windows 10 64 bit turned into a media-retrogaming living room PC.

    I use both emulators, old pc games and Steam games. I use two Playstation 3 controllers, connected with a bluetooth dongle and managed by the mighty ScpToolkit in order to emulate an Xbox360 controller. Why? Because I'm using both emulators and Steam games. Steam games only work with an Xbox360 controller and I didn't want to buy a new pair.

    Ok, let's move on. ScpToolkit needs a service to run properly but I don't want it to start everytime I start the pc, simply because I only need it when I play some games. And it makes the bluetooth dongle bling like a Christmas tree.

    So, I have created a bat file to instantly launch the Ds3Service by writing: sc start "Ds3Service". It works like a charm, but I have to run it as an administrator and click the UAC prompt. First world problems.

    Now here comes the real deal. I would like to create a bat file that launches firtst "Ds3Service_Start.cmd" as administrator (or the process itself withouth having to create a reserved cmd), with no UAC prompt, NO cmd window visible and with the capability of turning the cmd off after it ran. Than after the process is running and the cmd closed, the bat file should start Emulationstation.exe.

    I have already done some homework and I followed this guide to created an eleveted program shortcut. What I cannot do, even after reading the comment below, is to make the whole thing completely silent and to let it close itself.

    Here's what I get after running the shortcut created following the guide:

    C:\Windows\system32>sc start "Ds3Service"

    NOME_SERVIZIO: Ds3Service
    TIPO : 10 WIN32_OWN_PROCESS
    STATO : 2 START_PENDING
    (STOPPABLE, NOT_PAUSABLE, ACCEPTS_SHUTDOWN)
    CODICE_USCITA_WIN32 : 0 (0x0)
    CODICE_USCITA_SERVIZIO : 0 (0x0)
    PUNTO_CONTROLLO : 0x0
    INDICAZIONE_ATTESA : 0x0
    PID : 4028
    FLAG :

    C:\Windows\system32>

    and the cmd window stays there. I have tried to create a bat file with this inside:

    @echo off
    Start /MIN "" C:\Windows\System32\schtasks.exe /run /tn "Ds3Service_Start"
    exit

    With no luck. It correctly and instantly starts the process with no UAC prompt, but that window doesn't go away.

    Eternal glory to the super kind man who will be able to help me :)
      My Computer


  2. Posts : 4,187
    Windows 11 Pro, 22H2
       #2

    1) How are launching the batch file? Are you simply double-clicking the icon to execute it? If so, it should close after it is done and terminates. If you are simply running it from an open command prompt, than the command prompt would be expected to stay open since it was not opened by that batch file. If that's not what you are seeing, I would need to see the batch file.

    2) To avoid having to right=click and selecting "Run as administrator, you could add some code to the start of your batch file that will cause it to self-elevate. Here is a sample:

    Code:
    REM This sample shows how to create a self-elevating batch file.
    
    @echo off
    
    REM Change to directory where the batch file is located.
    cd /d %~dp0
    
    REM Check to see if this batch file is being run as Administrator
    
    openfiles > NUL 2>&1 
    if NOT %ERRORLEVEL% EQU 0 goto NotAdmin 
    goto IsAdmin
    
       :NotAdmin
    
    REM The batch file was not run as admin. Launch a new copy of the batch file as admin and close the current instance.
    
    powershell.exe start-process '%~f0' -verb runas
    exit
    
       :IsAdmin
    
    REM End Routine to check if being run as Admin
    REM Place any additional commands here. When you reach this point
    REM the batch file will be running elevated.
    REM End program
       :END
    Note that you may still get a UAC prompt depending upon what your UAC settings are. That, of course, is by design.
      My Computers


  3. Posts : 23
    Windows 10
    Thread Starter
       #3

    hsehestedt said:
    1) How are launching the batch file? Are you simply double-clicking the icon to execute it? If so, it should close after it is done and terminates. If you are simply running it from an open command prompt, than the command prompt would be expected to stay open since it was not opened by that batch file. If that's not what you are seeing, I would need to see the batch file.

    2) To avoid having to right=click and selecting "Run as administrator, you could add some code to the start of your batch file that will cause it to self-elevate. Here is a sample:

    Code:
    REM This sample shows how to create a self-elevating batch file.
    
    @echo off
    
    REM Change to directory where the batch file is located.
    cd /d %~dp0
    
    REM Check to see if this batch file is being run as Administrator
    
    openfiles > NUL 2>&1 
    if NOT %ERRORLEVEL% EQU 0 goto NotAdmin 
    goto IsAdmin
    
       :NotAdmin
    
    REM The batch file was not run as admin. Launch a new copy of the batch file as admin and close the current instance.
    
    powershell.exe start-process '%~f0' -verb runas
    exit
    
       :IsAdmin
    
    REM End Routine to check if being run as Admin
    REM Place any additional commands here. When you reach this point
    REM the batch file will be running elevated.
    REM End program
       :END
    Note that you may still get a UAC prompt depending upon what your UAC settings are. That, of course, is by design.
    Hey! Thank you for the super detailed answer! :)
      My Computer


  4. Posts : 4,187
    Windows 11 Pro, 22H2
       #4

    Glad to be able to help!
      My Computers


 

  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 11:46.
Find Us




Windows 10 Forums