달력

5

« 2024/5 »

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31

' 키 및 문자열 값 입력/업데이트
Set oArgs = WScript.Arguments

const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_
strComputer & "\root\default:StdRegProv")

strKeyPath = "SOFTWARE\<Key Name>"
oReg.CreateKey HKEY_LOCAL_MACHINE,strKeyPath

strValueName = "<Sting Value Name>"
strValue = oArgs(0)

oReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue



' 문자열 값 쿼리
const HKEY_LOCAL_MACHINE = &H80000002

strComputer = "."
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_
strComputer & "\root\default:StdRegProv")

strKeyPath = "SOFTWARE\<Key Name>"
strValueName = "<String Value Name 1>"
oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue1

strValueName = "<String Value Name 2>"
oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue2

If IsNull(strValue1) OR IsNull(strValue2) Then
WScript.Quit
End If

WScript.Echo strValue1
WScript.Echo strValue2

:
Posted by 커널64
2010. 2. 26. 08:50

VB Script를 이용한 SQL Lock 확인 (VBS) Etc.2010. 2. 26. 08:50

' 파라미터는 데이터베이스 이름
Dim oArgs
Set oArgs = WScript.Arguments

If oArgs.Count < 1 Then
WScript.Quit -1
End If

Dim dbcon, strCon, strDB, strSQL
strDB = oArgs(0)

Set dbcon = createobject("adodb.connection")
strCon = "provider=sqloledb;Data Source=localhost;Initial Catalog="&strDB&";Integrated Security=SSPI"

dbcon.open strCon
strSQL ="SELECT L.request_session_id AS SPID,DB_NAME(L.resource_database_id) AS DatabaseName,O.Name AS LockedObjectName,ST.text AS SqlStatementText,ES.login_name AS LoginName,ES.host_name AS HostName FROM sys.dm_tran_locks L JOIN sys.partitions P ON P.hobt_id = L.resource_associated_entity_id JOIN sys.objects O ON O.object_id = P.object_id JOIN sys.dm_exec_sessions ES ON ES.session_id = L.request_session_id JOIN sys.dm_tran_session_transactions TST ON ES.session_id = TST.session_id JOIN sys.dm_tran_active_transactions AT ON TST.transaction_id = AT.transaction_id JOIN sys.dm_exec_connections CN ON CN.session_id = ES.session_id CROSS APPLY sys.dm_exec_sql_text(CN.most_recent_sql_handle) AS ST WHERE resource_database_id = db_id() ORDER BY L.request_session_id"

Set Result = dbcon.execute(strSQL)

WScript.Echo "SPID | DatabaseName | LockedObjectName | SqlStatementText | LoginName | HostName"
Wscript.Echo "================================================================================"

Do while not Result.eof
strROW1 = Result(0)
strROW2 = Result(1)
strROW3 = Result(2)
strROW4 = Result(3)
strROW5 = Result(4)
strROW6 = Result(5)

If IsNull(strROW1) Then
strROW1 = "NULL"
End If
If IsNull(strROW2) Then
strROW2 = "NULL"
End If
If IsNull(strROW3) Then
strROW3 = "NULL"
End If
If IsNull(strROW4) Then
strROW4 = "NULL"
End If
If IsNull(strROW5) Then
strROW5 = "NULL"
End If
If IsNull(strROW6) Then
strROW6 = "NULL"
End If

WScript.Echo strROW1 & " | " & strROW2 & " | " & strROW3 & " | " & strROW4 & " | " & strROW5 & " | " & strROW6
Wscript.Echo "--------------------------------------------------------------------------------"

Result.movenext
loop

set Result = NOTHING
dbcon.close

:
Posted by 커널64

SCOM System Center Operations Manager VBS VBScript VB Script 클래스 인스턴스 Class Instance Discovery
아래는 특정 레지스트리 키와 문자열 값을 확인해 값이 있으면 해당 클래스의 인스턴스를 생성하고, 값이 없는 경우 다시 미등록 컴퓨터라는 클래스로 빠지게 하는 스크립트다.

' $MPElement$ $Target/Id$ $Target/Property[Type="Windows!Microsoft.Windows.Computer"]/PrincipalName$

Dim oAPI

Set oAPI = CreateObject("MOM.ScriptAPI")


Dim oArgs

Set oArgs = WScript.Arguments


If oArgs.Count < 3 Then

Call oAPI.LogScriptEvent("AppDiscovery.vbs",101,0, "Arguments Error.")

WScript.Quit -1

End If


Dim SourceID, ManagedEntityId, TargetComputer, oDiscoveryData, oInst

SourceId = oArgs(0)

ManagedEntityId = oArgs(1)

TargetComputer = oArgs(2)


Set oDiscoveryData = oAPI.CreateDiscoveryData(0, SourceId, ManagedEntityId)


const HKEY_LOCAL_MACHINE = &H80000002

Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")


strKeyPath = "SOFTWARE\TEST-SCOM"

oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,"Site",strSite

oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,"Process",strProcess

oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,"Line",strLine

oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,"Role",strRole

Set oReg=Nothing


If IsNull(strSite) OR IsNull(strProcess) OR IsNull(strLine) OR IsNull(strRole) OR strSite="" OR strProcess="" OR strLine="" OR strRole="" Then

' 미등록 컴퓨터 인스턴스 생성

Set oInst = oDiscoveryData.CreateClassInstance("$MPElement[Name='TEST.Unregistered']$")

Call oInst.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", TargetComputer)

Call oDiscoveryData.AddInstance(oInst)

Call oAPI.Return(oDiscoveryData)

WScript.Quit

End If


Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")

Set colItems = objWMIService.ExecQuery ("Select * from Win32_ComputerSystem")

For Each Item in colItems

strVendor = Item.Manufacturer

strModel = Item.Model

Next

Set colItems = objWMIService.ExecQuery ("Select * from Win32_OperatingSystem")

For Each Item in colItems

strOS = Item.Caption

strSP = Item.CSDVersion

Next

Set colItems = Nothing

Set objWMIService = Nothing


' TEST 설비 인스턴스 생성

Set oInst = oDiscoveryData.CreateClassInstance("$MPElement[Name='TEST.ALLEQUIP']$")

Call oInst.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", TargetComputer)

Call oInst.AddProperty("$MPElement[Name='TEST.ALLEQUIP']/Site$", strSite)

Call oInst.AddProperty("$MPElement[Name='TEST.ALLEQUIP']/Process$", strProcess)

Call oInst.AddProperty("$MPElement[Name='TEST.ALLEQUIP']/Line$", strLine)

Call oInst.AddProperty("$MPElement[Name='TEST.ALLEQUIP']/Role$", strRole)

Call oInst.AddProperty("$MPElement[Name='TEST.ALLEQUIP']/Vendor$", strVendor)

Call oInst.AddProperty("$MPElement[Name='TEST.ALLEQUIP']/Model$", strModel)

Call oInst.AddProperty("$MPElement[Name='TEST.ALLEQUIP']/OS$", strOS)

Call oInst.AddProperty("$MPElement[Name='TEST.ALLEQUIP']/SP$", strSP)

Call oDiscoveryData.AddInstance(oInst)

Call oAPI.Return(oDiscoveryData)

WScript.Quit

:
Posted by 커널64
2010. 2. 8. 20:32

컴퓨터 IP 주소 쿼리 - VBS(VB Script) Etc.2010. 2. 8. 20:32

strcomputer = "."
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colItems = objWMIService.ExecQuery("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = True")
For each objitem in colitems
strIPaddress = Join(objitem.IPAddress, ",")
WScript.Echo strIPaddress
Next
Set colItems = NOTHING

:
Posted by 커널64
2010. 1. 8. 13:21

폴더 크기 체크해서 파일로 찍기 (VBS) Etc.2010. 1. 8. 13:21

' Directory to Monitor
varPath = "C:\Windows"
varResultFile = "C:\DirSize.csv"

Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder(varPath)
SumFiles = f.size
SumFiles = SumFiles / 1048576
SumFiles = Round(SumFiles,2)
Set fso = NOTHING
Set f= NOTHING
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_OperatingSystem")
For Each objItem in colItems
    dtmLocalTime = objItem.LocalDateTime
    dtmMonth = Mid(dtmLocalTime, 5, 2)
    dtmDay = Mid(dtmLocalTime, 7, 2)
    dtmYear = Left(dtmLocalTime, 4)
    dtmHour = Mid(dtmLocalTime, 9, 2)
    dtmMinutes = Mid(dtmLocalTime, 11, 2)
    dtmSeconds = Mid(dtmLocalTime, 13, 2)
Next
strNow = dtmYear & "/" & dtmMonth & "/" & dtmDay & "," & dtmHour & ":" & dtmMinutes & ":" & dtmSeconds
Set objWMIService = NOTHING
Set colItems = NOTHING
Const ForAppending = 8
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile(varResultFile, ForAppending, True)
objTextFile.WriteLine(strNow&",Directory Size:,"&sumfiles&"MB")
objTextFile.Close
Set objFSO = NOTHING
Set objTextFile = NOTHING

:
Posted by 커널64

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colListOfServices = objWMIService.ExecQuery _
        ("Select * from Win32_Service")
For Each objService in colListOfServices
If (objService.StartMode = "Auto") and (objService.State = "Stopped") then

Set objShell = CreateObject("Wscript.Shell")
objShell.LogEvent 2, "Service " & objService.DisplayName & " is not running. (" & objService.Name & ")"
End If
Next

응용 프로그램 이벤트 로그

:
Posted by 커널64