1.

Solve : Get and use OS name.?

Answer»

I'm looking for a command what's doing this. IF the computer where the batch will run has the OS Vista the batch must open 1.cmd. And if the OS is XP the batch must open 2.cmd

Now I found WMIC OS GET CAPTION to get the OS name. How can i use this to do what I said?

Thanks in advancek this will work..

for /f "skip=1 tokens=1,1,5* delims=," %%a in ('wmic os get caption') do if "%%a"=='Microsoft© Windows VistaT Home Premium' GOTO :EX1

ok your gona need to no the different versions of windows your batch will be on in , in advance..
for me i use vista and the above code works.. if you type that into cmd just normally make sure to remember that were it says %%a , unless its a batch file theirs only one % symbol.. so the above code unless you use in a batch file wont work,


@ECHO OFF
:ARA
for /f "skip=1 tokens=1,1,5* delims=," %%a in ('wmic os get caption') do if "%%a"=='Microsoft© Windows VistaT Home Premium' GOTO :EX1
GOTO ARB

:ARB
for /f "skip=1 tokens=1,1,5* delims=," %%a in ('wmic os get caption') do if "%%a"=='Microsoft© Windows XP Home Edition' GOTO :EX2
GOTO DDN

:EX1
start cmd1.bat
GOTO DDN

:EX2
start cmd2.bat
GOTO DDN

:DDN
exit
Thanks man!

The choice COMMANDS use and understand I. But I think that this is enough

Quote

FOR /f "skip=1 tokens=3" %%i IN ('wmic os get caption') DO if "%%i"=="Vista" GOTO :Menu01

Only if someone have a Vista version (which doesn't matter he must goto menu01). All the other OS versions must goto menu1 (I have set that, not displayed here).

So this is enough? The WORD Vista is always set on the third token?yea it should work.. as far as i know it is, Except it's "VistaT". I believe, at least that is what is returned when I type in 'wmic os get caption'.Ok thanks man. I was thinking that Diablo has maked a typo.

Another thing:
My batch file is very big. I've see that I must make my batch file twice, because there are too many things other for Vista users. Maybe there is an other way.

Its most time about a command LIKE this:
Quote
FOR /f %%i IN ('DIR /b /a:d "%AppData%\Mozilla\Firefox\Profiles"') DO copy "%AppData%\Mozilla\Firefox\Profiles\%%i\*.*" "Profile"

I've heard (never RUNS Vista) its must be changed to (say if I'm wrong)
Quote
FOR /f %%i IN ('DIR /b /a:dh "%AppData%\Roaming\Mozilla\Firefox\Profiles"') DO copy "%AppData%\Roaming\Mozilla\Firefox\Profiles\%%i\*.*" "Profile"

So: is there a command that can change all the first commands to the second ones if the output of Quote
FOR /f "skip=1 tokens=3" %%i IN ('wmic os get caption') DO if "%%i"=="VistaT" GOTO :Menu??
is VistaT ?

Many thanksCode: [Select]C:\Users\DeltaSlaya>echo %appdata%
C:\Users\DeltaSlaya\AppData\Roaming

C:\Users\DeltaSlaya>
It appears that Vista includes the roaming folder in the appdata environment variable.

Also for me only the 'A' archive setting is present on all the folders in there, I am running vista.

Quote
cd %appdata%\mozilla\firefox\profiles
for /f "usebackq" %%I in (`dir /b /a:d`) do xcopy /e "%%I" "Profile"

I don't know but would that work?I can't find out of that works. But that is not my problem. I was looking for a command what can do this: Quote
Is there a command that can change all some commands automatically to some other commands; but only if the output of an other command is 'VistaT'

But now if I understand you right I see that the first command must also work for Vista users.
Quote
FOR /f %%i IN ('DIR /b /a:dh "%AppData%\Roaming\Mozilla\Firefox\Profiles"') DO copy "%AppData%\Roaming\Mozilla\Firefox\Profiles\%%i\*.*" "Profile"

Because you say the H is not needed, because the AppData folder is not hidden (other people say that the AppData folder is hidden in Vista.) And secondly the Roaming line is not needed because you say AppData includes Roaming. So the second command is exactly the same as the first, but that can not be: Because: The first command is well working for XP users, but not for Vista.

So what fault have you of I maked?

Quote from: Inferi0r on August 11, 2007, 04:59:45 AM
IF the computer where the batch will run has the OS Vista the batch must open 1.cmd. And if the OS is XP the batch must open 2.cmd
Code: [Select]Option Explicit
Dim strComputer,objOperatingSystem,objWMIService,colOperatingSystems ,WshShell, oExec,cmd
strComputer = "."
Set objWMIService = GETOBJECT("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colOperatingSystems = objWMIService.ExecQuery("Select * from Win32_OperatingSystem")
Set WshShell = CreateObject("WScript.Shell")
For Each objOperatingSystem in colOperatingSystems
If InStr(1,objOperatingSystem.Caption,"xp",1) Then
cmd="notepad"
ElseIf InStr(1,objOperatingSystem.Caption,"vista",1) Then
cmd="calc"
End If
Next
Set oExec = WshShell.Exec(cmd)
Do While oExec.Status = 0
WScript.Sleep 100
Loop
Looks very good ghostdog74

Do you have also a solution for my second problem: Quote
Is there a command that can change all some commands automatically to some other commands; but only if the output of an other command is 'VistaT'

Thanks in advance


Discussion

No Comment Found