1

I've seen there are a plethora of different posts and solutions regarding this specific issue, yet for some reason after implementing nearly all the results I've come across I'm still maddeningly enough getting the cannot find the path specific error for some reason.

Here's my script:

@echo off
set "params=%*"

cd /d "%~dp0" && ( if exist "%temp%\getadmin.vbs" del "%temp%\getadmin.vbs" ) && fsutil ^
    dirty query %systemdrive% 1>nul 2>nul || (  echo Set UAC = ^
    CreateObject^("Shell.Application"^) : UAC.ShellExecute "cmd.exe", "/k cd ""%~sdp0"" ^
    && %~s0 %params%", "", "runas", 1 >> "%temp%\getadmin.vbs" && "%temp%\getadmin.vbs" ^
    && exit /B )

echo Running custom startup tasks...
pause

runas "/user:*domainname*\*username* /savecred ^
    "C:\Program Files\EVGA\Precision X1" -s"

runas "/user:*domainname*\*username* /savecred ^
    "M:\Google Drive\Personal\Computer & Tech\Fixes &" Scripts\AHK\Home.ahk"

runas "/user:*domainname*\*username* /savecred ^
    "M:\Program Files (x86)\Steam\steam.exe""

runas "/user:*domainname*\*username* /savecred ^
    "M:\Program Files\Rainmeter\Rainmeter.exe""

echo Done!
pause
exit

Please note that I've redacted the parts within ** above for privacy.

7
  • Is M: a network drive, and is the idea behind this script to run as administrator?
    – LPChip
    Commented May 11, 2020 at 19:58
  • M:/ is a local HHD, not a mapped network drive. And yes, that is the idea, I have some startup programs that are in shell:startup but are not being launched at startup, so I'm attempting to fix that by using a .bat instead.
    – Arctiic
    Commented May 11, 2020 at 20:00
  • vbs will not understand this: && in: && %~s0 maybe : & %~s0
    – Io-oI
    Commented May 12, 2020 at 6:09
  • Why you need this single/odd double quotes here: ...& Tech\Fixes &" ... ???
    – Io-oI
    Commented May 12, 2020 at 6:41
  • @ItWasn'tMe The double-quote there was a misinput, but it's still throwing the same error without it. Regarding the & how can I escape it properly, assuming that's the cause to the error? I've already tried && as well, which doesn't work as you suspected.
    – Arctiic
    Commented May 12, 2020 at 7:37

2 Answers 2

1

Try changing the method mode used for elevating your bat to running as admin.

This one is a minimalist vbs that can help you elucidate if the error is in the bat or vbs code.

Try to run the bat commands directly on the command line, one by one, just to make sure that part / session is the error.

@echo off & setlocal EnableDelayedExpansion 

title <nul & title ..\%~nx0 & "%__APPDIR__%mode.com" 122,30 & color 0a & cd /d "%~dp0" 

2>nul "%__APPDIR__%whoami.exe" /groups | find "S-1-16-12288" >nul && goto :NXT: || <nul (
echo=CreateObject("Shell.Application"^).ShellExecute "%~sdpnx0", "%*", "RunAsAdministrator", "runas", 1: WScript.Quit
) >"%temp%\getadmin.vbs" && "%temp%\getadmin.vbs" //nologo && 2>nul del /q /f "%temp%\getadmin.vbs" && goto :eof

:NXT:
echo=Running custom startup tasks... <nul || "%__APPDIR__%timeout.exe" /t 3 >nul & echo\

echo\runas /user:*domainname*\*username* /savecred "C:\Program Files\EVGA\Precision X1\PrecisionX_x64.exe" -s
echo\runas /user:*domainname*\*username* /savecred "M:\Google Drive\Personal\Computer & Tech\Fixes & Scripts\AHK\Home.ahk"
echo\runas /user:*domainname*\*username* /savecred "M:\Program Files (x86)\Steam\steam.exe"
echo\runas /user:*domainname*\*username* /savecred "M:\Program Files\Rainmeter\Rainmeter.exe"

echo\Done^!! & "%__APPDIR__%timeout.exe" /t 5 & endlocal & goto :EOF
  • This is the vbs code without escaping:
CreateObject("Shell.Application").ShellExecute "C:\Users\ecker\AppData\Local\Temp\Q1C765~1.CMD", "arg1 arg2 arg3", "RunAsAdministrator", "runas", 1: WScript.Quit

// Note: To hide/suppress the cmd window while executions are in progress, change: "runas", 1  to "runas", 0 

Source/Inspiration in this answer by Riccardo La Marca

0
0

With this line:

runas "/user:*domainname*\*username* /savecred ^
    "C:\Program Files\EVGA\Precision X1" -s"

you're trying to 'runas' on a folder, looks as if you're missing an executable at the end of that, it's probably why the next line is the one throwing the error "I'm still getting 'M:\Google' is not recognized", the previous command is waiting for you to tell it what to runas

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .