데스크톱 관리를 위한 WMI 작업은 원격 데스크톱 또는 로컬 컴퓨터에서 제어하고 데이터를 가져올 수 있습니다. 예를 들어 로컬 컴퓨터의 화면 보호기에서 암호가 필요한지 여부를 확인할 수 있습니다. WMI는 원격 컴퓨터를 종료하는 기능도 제공합니다. 다른 예제는 https://www.microsoft.com/technetTechNet ScriptCenter를 참조하세요.
이 항목에 표시된 스크립트 예제는 로컬 컴퓨터에서만 데이터를 가져옵니다. 스크립트를 사용하여 원격 컴퓨터에서 데이터를 가져오는 방법에 대한 자세한 내용은 원격 컴퓨터 WMI에 연결하는참조하세요.
다음 절차에서는 스크립트를 실행하는 방법을 설명합니다.
스크립트 실행하려면
- 코드를 복사하고 .vbs 확장명(예: filename.vbs파일에 저장합니다. 텍스트 편집기가 파일에 .txt 확장자를 추가하지 않는지 확인합니다.
- 명령 프롬프트 창을 열고 파일을 저장한 디렉터리로 이동합니다.
- 명령 프롬프트에서 cscript filename.vbs 입력합니다.
- 이벤트 로그에 액세스할 수 없는 경우 관리자 권한 명령 프롬프트에서 실행 중인지 확인합니다. 보안 이벤트 로그와 같은 일부 이벤트 로그는 UAC(사용자 액세스 제어)로 보호될 수 있습니다.
메모
기본적으로 cscript는 명령 프롬프트 창에 스크립트의 출력을 표시합니다. WMI 스크립트는 많은 양의 출력을 생성할 수 있으므로 출력을 파일로 리디렉션할 수 있습니다. 명령 프롬프트에서 cscript filename.vbs > outfile.txt 입력하여 filename.vbs 스크립트의 출력을 outfile.txt리디렉션합니다.
다음 표에서는 로컬 컴퓨터에서 다양한 형식의 데이터를 가져오는 데 사용할 수 있는 스크립트 예제를 나열합니다.
| ... 원격 컴퓨터가 네트워킹 상태의 안전 모드에서 부팅되었는지 확인합니다. |
Win32_ComputerSystem 클래스를 사용하고 PrimaryOwnerName 속성의 값을 확인합니다.
strComputer = "."
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colSettings = objWMIService.ExecQuery ("Select * from Win32_ComputerSystem")
For Each objComputer in colSettings
Wscript.Echo "System Name: " & objComputer.Name
Wscript.Echo "Registered owner: " & objComputer.PrimaryOwnerName
Next
|
$colSettings = Get-WmiObject -Class Win32_ComputerSystem
foreach ($objComputer in $colSettings)
{
"System Name: " + $objComputer.Name
"Registered owner: " + $objComputer.PrimaryOwnerName
}
|
|
| ... 컴퓨터 화면 보호기에서 암호가 필요한지 확인합니다. |
Win32_Desktop 클래스를 사용하고 ScreenSaverSecure 속성의 값을 확인합니다.
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_Desktop")
For Each objItem in colItems
Wscript.Echo "Screen Saver Secure: " & objItem.ScreenSaverSecure
Next
|
$Computer = "."
$Desktops = Get-WMIObject -class Win32_Desktop -ComputerName $computer
"{0} desktops found as follows" -f $desktops.count
foreach ($desktop in $desktops) {
"Desktop : {0}" -f $Desktop.Name
"Screen Saver : {0}" -f $desktop.ScreensaverExecutable
"Secure : {0} " -f $desktop.ScreenSaverSecure
""
}
|
|
| ... 컴퓨터 화면이 800픽셀 x 600픽셀로 설정되었는지 확인하시겠습니까? |
Win32_DesktopMonitor 클래스를 사용하고 ScreenHeight 및 ScreenWidth 속성 값을 확인합니다.
strComputer = "."
Set objWMIService = GetObject(_
"winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_DesktopMonitor")
For Each objItem in colItems
Wscript.Echo "Screen Height: " & objItem.ScreenHeight
Wscript.Echo "Screen Width: " & objItem.ScreenWidth
Next
|
<# Get desktop information #>
$computer = "." $desktops = Get-WmiObject -Class Win32_DesktopMonitor $hostname = hostname
<# 데스크톱 세부 정보 표시 #> "다음과 같이 {1}{0} 데스크톱이 있습니다." -f $desktops. 이 시스템의 "" $i=1 # 데스크톱 개수 $hostname 개수
foreach ($desktop in $desktops) {
"Desktop {0}: {1}" -f $i++, $Desktop.Caption
"Screen Height : {0}" -f $desktop.ScreenHeight
"Screen Width : {0}" -f $desktop.ScreenWidth
""
}
|
|
| ... 컴퓨터가 얼마나 오래 실행되었는지 확인하시겠습니까? |
Win32_OperatingSystem 클래스와 LastBootUpTime 속성을 사용합니다. 시스템 작동 시간을 얻으려면 현재 시간에서 해당 값을 뺍니다.
strComputer = "."
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colOperatingSystems = objWMIService.ExecQuery ("Select * from Win32_OperatingSystem")
For Each objOS in colOperatingSystems
dtmBootup = objOS.LastBootUpTime
dtmLastBootUpTime = WMIDateStringToDate(dtmBootup)
dtmSystemUptime = DateDiff("h", dtmLastBootUpTime, Now)
Wscript.Echo dtmSystemUptime
Next
Function WMIDateStringToDate(dtmBootup)
WMIDateStringToDate = CDate(Mid(dtmBootup, 5, 2) & "/" & _
Mid(dtmBootup, 7, 2) & "/" & Left(dtmBootup, 4) & " " & Mid (dtmBootup, 9, 2) & ":" & _
Mid(dtmBootup, 11, 2) & ":" & Mid(dtmBootup, 13, 2))
End Function
|
함수 WMIDateStringToDate($Bootup) { [System.Management.ManagementDateTimeconverter]::ToDateTime($Bootup) }
<# 기본 스크립트 #> $Computer = "." # 필요에 따라 조정 $computers = Get-WMIObject -class Win32_OperatingSystem -computer $computer
foreach ($system in $computers) {
$Bootup = $system.LastBootUpTime
$LastBootUpTime = WMIDateStringToDate($Bootup)
$now = Get-Date
$Uptime = $now-$lastBootUpTime
"System Up for: {0}" -f $UpTime
}
|
|
| ... 원격 컴퓨터를 다시 부팅하거나 종료하시겠습니까? |
Win32_OperatingSystem 클래스와 Win32Shutdown 메서드를 사용합니다. WMI에 연결할 때 RemoteShutdown 권한을 포함해야 합니다. 자세한 내용은 VBScript 사용하여 권한 있는 작업 실행참조하세요.
Win32_OperatingSystemShutdown 메서드와 달리 Win32Shutdown 메서드를 사용하면 종료 동작을 제어하는 플래그를 설정할 수 있습니다.
strComputer = "atl-dc-01"
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate,(Shutdown)}!\\" & strComputer & "\root\cimv2")
Set colOperatingSystems = objWMIService.ExecQuery ("Select * from Win32_OperatingSystem")
For Each objOperatingSystem in colOperatingSystems
ObjOperatingSystem.Shutdown(1)
Next
|
strComputer = "atl-dc-01"
$colOperatingSystem = Get-WmiObject -Class Win32_OperatingSystem -ComputerName $strComputer -Namespace "wmi\cimv2"
foreach ($objOperatingSystem in $colOperatingSystem)
{
[void]$objOperatingSystem.Shutdown()
}
|
|
| ... Windows를 시작할 때마다 자동으로 실행되는 애플리케이션을 결정하나요? |
Win32_StartupCommand 클래스를 사용합니다.
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")
Set colStartupCommands = objWMIService.ExecQuery _
("Select * from Win32_StartupCommand")
For Each objStartupCommand in colStartupCommands
Wscript.Echo "Command: " & objStartupCommand.Command & VBNewLine _
& "Description: " & objStartupCommand.Description & VBNewLine _
& "Location: " & objStartupCommand.Location & VBNewLine _
& "Name: " & objStartupCommand.Name & VBNewLine _
& "SettingID: " & objStartupCommand.SettingID & VBNewLine _
& "User: " & objStartupCommand.User
Next
|
$strComputer = "."
$colItems = Get-WmiObject -Class Win32_StartupCommand -ComputerName $strComputer
foreach ($objStartupCommand in $colItems)
{
"Command: " + $objStartupCommand.Command
"Description: " + $objStartupCommand.Description
"Location: " + $objStartupCommand.Location
"Name: " + $objStartupCommand.Name
"SettingID: " + $objStartupCommand.SettingID
"User: " + $objStartupCommand.User
}
|
|
-
스크립트 및 애플리케이션 대한 WMI 작업
-
WMI C++ 애플리케이션 예제
-
TechNet ScriptCenter