Batch file issue setting SID to variable.

March 13, 2012 at 13:25:47
Specs: Windows 7 64 bit
I am having an issue with this batch file and cant seem to find where I went wrong.
What is happening in this script.
I am setting the users SID to the variable SID.
I am using that variable to add 2 registry keys.

The issue is that I am getting an extra space on the end of the the SID. My eyes hurt from looking at this for to long. (I removed a lot of the hex binary form the reg key make this smaller)

Here is the currect script.

@echo off
reg query "HKLM\software\microsoft\windows nt\currentversion\profilelist" /s >>"%temp%\reg_sid.txt"
findstr /n /i %username% "%temp%\reg_sid.txt">>"%temp%\sid_number.txt"
for /f "tokens=1 delims=:" %%i in (%temp%\sid_number.txt) do set line_num=%%i
set /a line_num=%line_num% - 2
for /f "skip=%line_num% tokens=7 delims=\" %%i in (%temp%\reg_sid.txt) do set sid=%%i & goto :continue
:continue
rem for /l %%i in (1,1,12) do echo.
rem echo %sid:~0,-1%
rem for /l %%i in (1,1,11) do echo.
del "%temp%\reg_sid.txt"
del "%temp%\sid_number.txt"

REG ADD "HKU\%sid%\Printers\Connections\,,xxx,CC 5051M" /v DefaultDevMode /t REG_BINARY /d 5c00

REG ADD "HKU\%sid%\Printers\Connections\,,xxx,CC 5051M" /v DevMode /t REG_BINARY /d 5c00


See More: Batch file issue setting SID to variable.

Report •


#1
March 13, 2012 at 14:07:40
Question: Why not just use the current user binding (HKCU)?
@REG ADD "HKCU\Printers\Connections\,,xxx,CC 5051M" /v DefaultDevMode /t REG_BINARY /d 5c00
@REG ADD "HKCU\Printers\Connections\,,xxx,CC 5051M" /v DevMode /t REG_BINARY /d 5c00

How To Ask Questions The Smart Way


Report •

#2
March 14, 2012 at 04:39:02
I can not use the HKCU The printer uses the HKU (HKEY_Users) for some odd reason.

Report •

#3
March 14, 2012 at 08:15:30
FIxed after going back and looking at every line.
Made a change at the end

reg query "HKLM\software\microsoft\windows nt\currentversion\profilelist" /s >>"%temp%\reg_sid.txt"
findstr /n /i %username% "%temp%\reg_sid.txt">>"%temp%\sid_number.txt"
for /f "tokens=1 delims=:" %%i in (%temp%\sid_number.txt) do set line_num=%%i
set /a line_num=%line_num% - 2
for /f "skip=%line_num% tokens=7 delims=\" %%i in (%temp%\reg_sid.txt) do set sid=%%i & goto :continue
:continue
for /f "tokens=* delims= " %%A in ('echo %SID%') do set SID=%%A
set SID=%SID:~0,-1%
del "%temp%\reg_sid.txt"
del "%temp%\sid_number.txt"


Report •

Related Solutions

#4
March 14, 2012 at 11:42:25
The printer uses the HKU (HKEY_Users) for some odd reason.
Right, and HKCU is bound to your HKU key.

How To Ask Questions The Smart Way


Report •


Ask Question