none
Trying to run batch file in MDT fails, but succeeds manually. RRS feed

  • Question

  • I addressed this once in the past but never figured out a solution...

    I have a batch file (below) which changes the values of 3G and 4G in the registry from 2 to 1. You must first take ownership to make the changes.
    If I run this manually, it works. I am not sure I have it set up correctly for MDT to execute it.

    The file gets copied to a folder in C:\. It does succeed running it manually on the pc. The file is (SETACL.bat):

    Reg Query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkList\DefaultMediaCost" /v 3G
    If %ERRORLEVEL% GEQ 1 GOTO 4G
    
    :SETUP ACL FOR 3G
    SetACL -on "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkList\DefaultMediaCost" -ot reg -actn setowner -ownr "n:Administrators"
    
    SetACL -on "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkList\DefaultMediaCost" -ot reg -actn ace -ace "n:Administrators;p:full"
    
    SetACL -on "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkList\DefaultMediaCost" -ot reg -actn setowner -ownr "n:NT Service\TrustedInstaller"
    
    SetACL -on "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkList\DefaultMediaCost" -ot reg -actn ace -ace "n:NT Service\TrustedInstaller;p:full"
    
    reg add "HKLM\Software\Microsoft\Windows NT\CurrentVersion\NetworkList\DefaultMediaCost" /v 3G /t REG_DWORD /d 1 /f
    
    
    
    :SETUP ACL FOR 4G
    
    :4G
    Reg Query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkList\DefaultMediaCost" /v 4G
    If %ERRORLEVEL% GEQ 1 GOTO END
    
    SetACL -on "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkList\DefaultMediaCost" -ot reg -actn setowner -ownr "n:Administrators"
    
    SetACL -on "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkList\DefaultMediaCost" -ot reg -actn ace -ace "n:Administrators;p:full"
    
    SetACL -on "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkList\DefaultMediaCost" -ot reg -actn setowner -ownr "n:NT Service\TrustedInstaller"
    
    SetACL -on "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkList\DefaultMediaCost" -ot reg -actn ace -ace "n:NT Service\TrustedInstaller;p:full"
    
    reg add "HKLM\Software\Microsoft\Windows NT\CurrentVersion\NetworkList\DefaultMediaCost" /v 4G /t REG_DWORD /d 1 /f
    
    :END
    


    The next step is a simple bat file to execute the one above:

    runas /user:administrator
    START C:\Fixes\OutlookMeterFix\SETACL.bat
    exit

    I believe the step above is wrong and fails to execute SETACL.bat correctly.
    The values only change if I run the SETACL.bat from the desktop outside of MDT. I'm hoping it gets copied over and runs
    successfully all within the TS.
    Thanks

    Monday, October 29, 2018 1:59 PM

Answers

  • I made a PS script below to kick off my batch file. There is likely a better way, ie adding the contents of my batch INTO the PS, but this is working.

    Start-Process C:\path to file\file.bat

     
    • Marked as answer by the1rickster Monday, October 29, 2018 5:53 PM
    Monday, October 29, 2018 5:53 PM

All replies

  • Update to this....

    With little PS knowledge, I did find a PS script to use as a template:

    $cmd="C:\path to file\SETACL.bat"
    & $cmd

    From here, I get NotSpecified: CMD.exe was started with the above path as the current directory (\\mdtserver\etc...) UNC paths are not supported.

    I guess I just need to alter the PS to reference the target C:\ correctly...

    I did try $cmd="$env:SystemDrive\path....\" but it has the same result.


    HOWEVER, it does change the values. I just don't understand the error or a solution.
    Monday, October 29, 2018 5:06 PM
  • I made a PS script below to kick off my batch file. There is likely a better way, ie adding the contents of my batch INTO the PS, but this is working.

    Start-Process C:\path to file\file.bat

     
    • Marked as answer by the1rickster Monday, October 29, 2018 5:53 PM
    Monday, October 29, 2018 5:53 PM