1
I am trying to make a custom tool that works with Steam. Because the user may have a different install directory than myself, I want to use the SteamPath
registry string value as a variable in my batch code to get the correct path. I am attempting to use the code below to make my custom STEAMDIR
variable:
@ECHO OFF
SETX STEAMDIR /K "HKEY_CURRENT_USER\Software\Valve\Steam\SteamPath" /m
IF NOT EXIST "STEAMDIR" GOTO :NOSTEAM
IF EXIST "STEAMDIR" GOTO :FOUND
:FOUND
CLS
SET msgboxTitle=Success!
SET msgboxBody=Steam found!
SET tmpmsgbox=%TEMP%\Message.vbs
IF EXIST "%tmpmsgbox%" DEL /F /Q "%tmpmsgbox%"
ECHO msgbox "%msgboxBody%",0,"%msgboxTitle%">"%tmpmsgbox%"
WScript "%tmpmsgbox%"
GOTO :END
:NOSTEAM
CLS
SET msgboxTitle=Error!
SET msgboxBody=You don't kave any Kenshi workshop mods installed!
SET tmpmsgbox=%TEMP%\Message.vbs
IF EXIST "%tmpmsgbox%" DEL /F /Q "%tmpmsgbox%"
ECHO msgbox "%msgboxBody%",0,"%msgboxTitle%">"%tmpmsgbox%"
WScript "%tmpmsgbox%"
GOTO :END
:END
I am to use SETX
as demonstrated IN this SS64 page, but my attempts have been unsuccessful. Any help is appreciated, but I'd like to ask that solutions using PowerShell or VisualBasic not be suggested. I get these a lot and I do not have enough experience in either language to re-write my code as I still have things to add.
But you're already running VBScript from within your batch script. – user1686 – 2019-03-06T07:59:00.190
I am aware @grawity, it was made from a template using an answer I received on a different question. I will be adding
XCOPY
programming that is in batch and I do not know how to translate it. – Mr. Mendelli – 2019-03-06T08:00:52.583You can still run the same xcopy.exe from within any other programming language, and I would honestly suggest that the overall framework better be written in something not requiring such arcane hacks as
for /f
to do even trivial operations. Port it while it's still small. – user1686 – 2019-03-06T08:15:31.600I will have to decline your suggestion, I do not have the time right now to learn another language. – Mr. Mendelli – 2019-03-06T08:17:12.043
1I'd suggest you to read a help for
set
command. You do the assignment completely wrong. – montonero – 2019-03-06T08:28:08.6301If you don't mind it requiring a second run you can set it with
setx
which can parse a value directly from the registry. – shawn – 2019-03-06T08:36:11.320