I want to set the output in a string from this windows command in evelated command sc sdshow mslldp but get only the first entry. Have anyone an idea?
Have already this:
C:\TMP>FOR /F "tokens=*" %a in ('test.cmd') do SET OUTPUT=%a
C:\TMP>SET OUTPUT=C:\TMP>sc sdshow mslldp
C:\TMP>SET OUTPUT=D:(D;;CCDCLCSWRPWPDTLOCRSDRCWDWO;;;BG)(A;;CCDCLCSWRPWPDTLOCRSDRCWDWO;;;SY)(A;;CCDCLCSWRPDTLOCRSDRCWDWO;;;BA)(A;;CCLCSWRPWPDTLOCRRC;;;SO)(A;;LCRPWP;;;S-1-5-80-3141615172-2057878085-1754447212-2405740020-3916490453)
And now I want to add an own (A;;CCLCSWLOCRRC;;;SU) parameter with sc sdset mslldp.
Related
I need to list all services with a special name and a index and their autostart status. My thoughts were to use a batch and something like sc query but this doesn't give me the required information.
This is what I tried
sc query service
sc query service2
sc query service3
pause
Which command is suitable to list the start setting for a service?
I would rather use powershell, as sc query does not display startup type by default:
To see startup type by Display name, open cmd.exe and type (or paste):
powershell "Get-Service | select -property displayname,starttype"
or by actaul service name:
powershell "Get-Service | select -property name,starttype"
or you can create a powershell script by creating a file and give it a .ps1 extension and adding:
Get-Service | select -property name,starttype
or if you really want to use batch file, simply create a batch file with .cmd or .bat extension and add:
powershell "Get-Service | select -property name,starttype"
But, if you really are determined to use batch, you can run this which runs 2 for loops, one to get all the services, second will get the startup type of each. the set's are simply there to cleanup some unwanted items.
#echo off
setlocal enabledelayedexpansion
for /f "tokens=1,2 delims=:" %%i in ('sc query ^|findstr "SERVICE_NAME"') do (
set serv=%%j
set serv=!serv: =!
for /f "tokens=1,2 delims=:" %%a in ('sc qc !serv! ^| findstr "START_TYPE"') do set type=%%b
set type=!type: =!
set type=!type:1=!
set type=!type:2=!
set type=!type:3=!
echo !serv! : !type!
)
I need to deploy windows images to several computers that came with Windows 8.1.
I did manage to inject drivers and updates and some necessary softwares to the installation image, but somehow it seems that just installing Windows won't activate the operating system, and I have to find the license keys embedded in the BIOS and activate them manually.
I found out that wmic path softwarelicenseingservice get oa3xoriginalproductkey could be used to extract the product key from the bios, and I am thinking about composing a batch file that uses this command in joint with slmgr -ipk and slmgr -ato, and then make it run as the firstlogon command.
The trouble is that I don't know a lot about batch syntax, and I am having a hard time assigning the product key as a variable and passing it over to slmgr commands.
It seems that the wmic command returns the result as:
OA3xOriginalProductKey
XXXXX-XXXXX-XXXXX-XXXXX-XXXXX
<blank line>
So there it returns the product key in a three line text, with the actual useful information sandwiched between other strings. How can I just get the middle(or second) line from this text and assign it as a variable?
Maybe this will work for you. Note it does involve a temporary text file.
wmic path softwarelicenseingservice get oa3xoriginalproductkey > temp.txt
3<temp.txt (
set /p var= <&3
set /p var= <&3
)
del temp.txt
Echo %var%
Which will always extract the second line of output from the command.
I have tested this with the data you provided and it outputted XXXXX-XXXXX-XXXXX-XXXXX-XXXXX. TO access this variable always refer to it as %var%.
Here's how i would do it
Logon scripts accept powershell scripts which has much more features and strength in it than the old batch files.
$key = Get-WmiObject -Class SoftwareLicensingService |
Select-Object OA3xOriginalProductKey | foreach { "{0}" -f $_.OA3xOriginalProductKey }
with this command, you get your ProductID into the $key variable and free to do any manipulation you'd like with it
cscript.exe C:\Windows\System32\slmgr.vbs /upk
cscript.exe C:\Windows\System32\slmgr.vbs /cpky
for /f "tokens=2 delims='='" %%K IN ('wmic path softwarelicensingservice get OA3xOriginalProductkey /value') do set pk=%%K
cscript.exe C:\Windows\System32\slmgr.vbs /ipk %pk%
cscript.exe C:\Windows\System32\slmgr.vbs /ato
cscript.exe C:\Windows\System32\slmgr.vbs /dli
save this as batch file and try
This is what I needed.
It works perfect.
for /f "tokens=2 delims='='" %%K IN ('wmic path softwarelicensingservice get OA3xOriginalProductkey /value') do set pk=%%K
slmgr.vbs /ipk "%pk%"
slmgr.vbs /ato
Im using the sc command to query the services running on machines and was using code similar to:
sc \\"server_name" query | find "SERVICE_NAME" > servicelist2.txt
so basically all the server names are listed in this one notepad file. there are 100+ of them. it is too hard to manually put each name in and write 100+ lines of code. is there a way i can use batch itself to direct to the notepad file and iterate through all the server names written in it and then put them back into the "sc" command?
EDIT: Am on windows btw if it wasnt obvious. Using batch scripts for the above.
Assuming you have a file named servers.list in the same directory, you can use this:
for /f %%a in (%~d0%~p0servers.list) do (
ECHO %%a > servicelist2.txt
sc \\%%a query | find "SERVICE_NAME" > servicelist2.txt
)
you can do this with for /f :
OR /F "usebackq tokens=*" %%G IN ("C:\My Documents\servers.txt") DO (
sc \\%%G query | find "SERVICE_NAME" > servicelist2.txt
)
#echo off
echo Starting to list query services...
for /f %%i in (servieslist2.txt) do sc query %%i > output.txt
echo Finished query services...
The above will loop through each of the 100 service names specified in serviceslist2.txt and output it to a file called output.txt in the same directory as the batch file
I want to be able to check whether or not Tomcat is currently already running as a service. The problem is that I'm not sure what the name of the service will be.
I plan to look in another batch file from where Tomcat is started.
In that file there is the line:
#echo off
rem START or STOP Tomcat
....
sc start "TomcatService5"
Is there an easy way to read that file and parse out the service name argument passed into the command "sc start"?
The following code searches for the line sc start in the file start.cmd and gets the 3rd token from that line:
for /F "tokens=3" %%a in ('findstr /L "sc start" start.cmd') do echo %%a
I am running the following command to get Tomcat location from the Registry.
for /f "tokens=2 delims=REG_SZ" %t in ('reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Apache Software Foundation\Tomcat\5.5" /v InstallPath | find "REG_SZ"') do set drive=%t
The output is set drive= C:\Tomcat 5.5
It looks like the the chars between = and C:\ are not spaces, since my command to substitute spaces for nothing: set drive=%drive: =% does not work.
Any suggestions?
It is a tab. Replacing works only in a batch file.
set drive=%drive: =%