Dim WshShell : Set WshShell = WScript.CreateObject("WScript.Shell")
Return = WshShell.RegRead(strRegName)
Return = WshShell.RegRead("HKCU\Software\Microsoft\Notepad\lfFaceName") ' 굴림
Return = WshShell.RegRead("HKCU\Software\Winamp\") ' C:\Program Files\Winamp
Return = WshShell.RegRead("HKCU\Software\WinRAR\") ' 기본값 없어서 에러 발생.
- strRegName : key or value-name
' strRegName의 루트키 약자
HKEY_CURRENT_USER : HKCU
HKEY_LOCAL_MACHINE : HKLM
HKEY_CLASSES_ROOT : HKCR
HKEY_USERS : HKEY_USERS
HKEY_CURRENT_CONFIG : HKEY_CURRENT_CONFIG
' 레지스트 경로의 마지막에 백슬래시 \ 가 있으면 키, 없으면 값의 이름을 가리킨다.
' 키나 값이 존재하지 않을 경우, 값이 바이너리값인 경우 -> 에러 발생.
' 키의 default value 가 존재하지 않을 경우 -> 에러 발생.
' REG_SZ 값은 String 을 읽어온다.
' REG_DWORD 값은 dword 값이 아닌 실제 정수값을 읽어온다.
' REG_BINARY 값은 읽지 못한다. (에러 발생)
' REG_EXPAND_SZ 값은 String 문자열 그대로 읽어온다.
=========================================================
WshShell.RegWrite strRegName, anyValue [, strType]
- strRegName : key or value-name
' 키 추가 : strRegName에 \ 를 붙여준다.
' 이름 추가 : strRegName에 \ 를 붙이지 않음.
' strRegName에 \ 붙이고 Value 가 공백(zero-length string) 이면 빈 새 키가 생성된다
- anyValue
' value에 Dword 값 입력시에는 dowrd값이 아닌 실제 정수(십진수)로 입력해야 함.
' value에 쌍따옴표 포함된 String 입력시 다시 쌍따옴표로 감싸주거나 Chr(34) 를 이용한다.
' value에 경로문자 \가 포함된 String 입력시 \ 는 \\ 로 바꿔 입력할 필요가 없다.
' value에 환경변수 포함된 String 입력하면 변환된 값이 아닌 환경변수 문자열 그대로 입력된다.
- strType (Registry Data Type)
REG_SZ : 문자열 (String)
REG_DWORD : 정수 (Integer)
REG_EXPAND_SZ : 문자열 ( %comspec% 등과 같은 환경 변수를 포함하는 경우)
REG_BINARY : 이진 문자열
' 값의 형식 지정하지 않으면 REG_SZ 로 인식
' REG_MULTI_SZ 값 입력은 지원되지 않음.
WshShell.RegWrite "HKCU\Software\AAA\", "" ' 빈 새키 생성
WshShell.RegWrite "HKLM\...\ValName", 1000, "REG_DWORD" ' dword:000003e8 입력시
WshShell.RegWrite "HKCU\..", """%ProgramFiles%\..""", "REG_EXPAND_SZ"
Dim WshEnv : Set WshEnv = WshShell.Environment("Process")
Dim ProgramDir : ProgramDir = WshEnv("ProgramFiles")
WshShell.RegWrite "HKCU\..", Chr(34) & ProgramDir & "\some.txt" & Chr(34), "REG_SZ"
' REG_EXPAND_SZ타입은 %~%를 문자열 그대로 입력.
' 맞는 값으로 변환시켜 입력하려면 Environment 등을 이용하여 값을 얻어 입력해야 함.
=========================================================
WshShell.RegDelete strRegName
- strName : key or value-name
WshShell.RegDelete "HKCU\MyNewKey\" ' 키 삭제 : 맨 뒤에 \ 를 붙여준다
WshShell.RegDelete "HKCU\MyNewKey\MyValue" ' 이름 삭제 : 맨 뒤에 \ 를 붙이지 않음
' 레지스트리 읽어서 .reg 파일로 저장
Set WshShell = CreateObject("WScript.Shell")
sKey = "HKEY_CURRENT_USER\Software\Microsoft\Notepad"
fName = "c:\TEMP\FirstPage.reg"
sCmd = "regedit /e/a " & Chr(34) & fName & Chr(34) & " " & Chr(34) & sKey & Chr(34)
WshShell.Run "%comspec% /c " & sCmd, 0, True
Set WshShell = Nothing
'================================================================
' 레지스트리 파일 읽어서 Program Files 경로 변경 후 병합하기
Option Explicit
'On Error Resume Next
'Err.Clear
Dim Shell : Set Shell = WScript.CreateObject("WScript.Shell")
Dim FSO : Set FSO = WScript.CreateObject("Scripting.FileSystemObject")
Dim ProgramDir : ProgramDir = Shell.Environment("Process").Item("ProgramFiles")
Const FindLong = "C:\\Program Files"
Const FindShort = "C:\\PROGRA~1"
Dim ProgArray, ProgLong, ProgShort
ProgArray = Split (ProgramDir, "\")
ProgLong = ProgArray(1)
ProgShort = ProgArray(1)
If Len(ProgLong) > 8 Then
ProgShort = Left(ProgLong, 6) & "~1" ' PROGRA~1
End If
Dim RepLong : RepLong = ProgArray(0) & "\\" & ProgLong
Dim RepShort : RepShort = ProgArray(0) & "\\" & ProgShort
' 레지파일의 경로 구분자는 \가 아닌 \\
Dim RegFile : RegFile = "install.reg"
Dim ts, strLine, newLine
Dim newReg : newReg = ""
If FSO.FileExists(RegFile) Then
Set ts = FSO.OpenTextFile(RegFile, 1) ' 1 => ForReading
Do Until ts.AtEndOfStream
strLine = ts.ReadLine
newLine = Replace(strLine, FindLong, RepLong, 1, -1, 1)
newLine = Replace(newLine, FindShort, RepShort, 1, -1, 1)
newReg = newReg & newLine & vbCrLf
Loop
ts.Close
Dim fTmp : fTmp = FSO.GetAbsolutePathName(FSO.GetTempName)
FSO.CreateTextFile(fTmp)
Dim getTmp : Set getTmp = FSO.GetFile(fTmp)
Dim tsTmp : Set tsTmp = getTmp.OpenAsTextStream(2, True) ' Const ForWriting = 2
tsTmp.Write(newReg): tsTmp.Close
Shell.Run "%COMSPEC% /C regedit /s " & Chr(34) & fTmp & Chr(34), 0, True
FSO.DeleteFile fTmp, True
End If
Set Shell = Nothing
Set FSO = Nothing
WScript.Quit
'================================================================
' 프로그램 설치되었는지 여부 검사하기
Set WshShell = CreateObject("WScript.Shell")
If WshShell.RegRead("HKCR\.BMP\\") = "ACDC_BMP" Then
WScript.Echo "ACDSee installed."
Else
WScript.Echo "You can install ACDSee."
End If
Set WshShell = Nothing
- [Method] SendKeys
Dim WshShell : Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.SendKeys string[, wait]
string : 필수. 입력된 문자식을 보냅니다.
Wait : 선택. 부울 값은 대기 모드로 지정합니다.
False (기본값)이면 키가 입력이 되면 컨트롤은 바로 프로시저에 반환됩니다.
True 이면 프로시저에게 컨트롤이 반환되기 전에 반드시 키가 입력되어야 합니다.
--------------------------------------------------------------------------
* 문자 입력 : 그 문자 자체를 표시.
예) ABC => "ABC"
* 기호 문자 입력 : 중괄호({})로 묶어준다.
예) 덧셈 기호를 입력 => {+}
더하기 기호 plus sign +
삽입 기호 caret ^
퍼센트 기호 percent sign %
생략 기호 and tilde ~
괄호 ( )
cf, 대괄호([ ]) : 대괄호는 그냥 입력이 가능하지만, 다른 응용프로그램에서 특수하게
인식될수 있으므로 중괄호로 묶어준다.
[ => {{} ] => {}}
* 특수 키 입력
키 코드
백스페이스 {BACKSPACE}, {BS} 또는 {BKSP}
Break {BREAK}
Caps Lock {CAPSLOCK}
Del 또는 Delete {DELETE} 또는 {DEL}
아래쪽 화살표 {DOWN}
End {END}
Enter {ENTER} 또는 ~
Esc {ESC}
Help {HELP}
Home {HOME}
Ins 또는 Insert {INSERT} 또는 {INS}
왼쪽 화살표 {LEFT}
Num Lock {NUMLOCK}
Page Down {PGDN}
Page Up {PGUP}
Print Screen {PRTSC}
오른쪽 화살표 {RIGHT}
Scroll Lock {SCROLLLOCK}
Tab {TAB}
위쪽 화살표 {UP}
F1 {F1}
F2 {F2}
F3 {F3}
F4 {F4}
F5 {F5}
F6 {F6}
F7 {F7}
F8 {F8}
F9 {F9}
F10 {F10}
F11 {F11}
F12 {F12}
F13 {F13}
F14 {F14}
F15 {F15}
F16 {F16}
* Shift,Ctrl,Alt 와 일반 키를 동시에 누를 경우 : 아래 문자를 입력할 키 앞에 붙여준다.
Shift +
Ctrl ^
Alt %
조합키 누른채 다른 여러 키를 입력해야 한다면 여러 키들을 괄호로 묶어준다.
Shift + ( E + C...) => "+(ec)"
(Shift + E) + C => "+ec"
Alt + F4 => "%{F4}"
* 키 반복 입력 : 반복되는 키를 지정할 때는 {keystroke number}의 형식으로 나타낸다.
(키와 숫자 사이에 반드시 공백 필요)
왼쪽 화살표키를 42회 입력 => {LEFT 42}
H를 10 번 입력 => {h 10}
Ctrl+X 를 10번 입력하는 식으로 특수키와 일반키의 조합을 여러번 입력하는건 안된다.
alt + ctrl + del => Shell.Sendkeys("%^{DEL}") x
Shell.Sendkeys("%^+{DEL}") o
* 참고 *
Microsoft Windows 내에서 실행되지 않는 응용 프로그램에 SendKeys를 사용하여 키를
입력할 수 없다.
Sendkeys는 또한 PRINT SCREEN key {PRTSC} 를 다른 응용 프로그램에 보낼 수 없다.
- [Method] Run, Exec
Dim WshShell : Set WshShell = CreateObject("WScript.Shell")
intError = WshShell.Run (strCommand [, intWindowStyle] [, bWaitOnReturn])
WshShell.Run "%windir%\notepad" & WScript.ScriptFullName
' cf, 반환값 없이 단독 실행시에는 괄호로 묶지 않는다.
intError = WshShell.Run("notepad " & WScript.ScriptFullName, 1, True)
intError = WshShell.Run ("setup.exe", 1, true)
- object : WshShell object.
- strCommand : String value indicating the command line you want to run.
- intWindowStyle : Optional. Integer value indicating the appearance of the program's window.
* intWindowStyle :
0 Hides the window and activates another window.
1 Activates and displays a window.
If the window is minimized or maximized, the system restores it to its original size and position.
An application should specify this flag when displaying the window for the first time.
2 Activates the window and displays it as a minimized window.
3 Activates the window and displays it as a maximized window.
4 Displays a window in its most recent size and position.
The active window remains active.
5 Activates the window and displays it in its current size and position.
6 Minimizes the specified window and activates the next top-level window in the Z order.
7 Displays the window as a minimized window. The active window remains active.
8 Displays the window in its current state. The active window remains active.
9 Activates and displays the window.
If the window is minimized or maximized, the system restores it to its original size and position.
An application should specify this flag when restoring a minimized window.
10 Sets the show-state based on the state of the program that started the application.
- bWaitOnReturn : Optional. (true / false)
Boolean value indicating whether the script should wait for the program to finish executing
before continuing to the next statement in your script.
If set to true, script execution halts until the program finishes, and Run returns any error code returned by the program.
If set to false (the default), the Run method returns immediately after starting the program,
automatically returning 0 (not to be interpreted as an error code).
- intError : Error code ( integer ).
-----------------------------------------------------------------------------------
Dim WshShell : Set WshShell = CreateObject("WScript.Shell")
Dim oExec : Set oExec = WshShell.Exec("calc")
Do While oExec.Status = 0
WScript.Sleep 100
Loop
WScript.Echo oExec.Status
' Status Return Values
' 0 : The job is still running.
' 1 : The job has completed.
-----------------------------------------------------------------------------------
' Run 과 Exec 의 가장 큰 차이
'=> Run 은 실행만 하지만, Exec는 실행과 동시에 객체(object)를 생성한다.
' 따라서 Exec를 통한 실행은 생성된 객체를 이용한 후속 작업이 용이하다.
Set FSO = Wscript.CreateObject("Scripting.FileSystemObject")
Set Shell = Wscript.CreateObject("Wscript.Shell")
TempName = FSO.GetTempName
TempFile = TempName
Shell.Run "cmd /c ping -n 3 -w 1000 157.59.0.1 >" & TempFile, 0, True
Set TextFile = FSO.OpenTextFile(TempFile, 1)
Do While TextFile.AtEndOfStream <> True
strText = TextFile.ReadLine
If Instr(strText, "Reply") > 0 Then
Wscript.Echo "Reply received."
Exit Do
End If
Loop
TextFile.Close
FSO.DeleteFile(TempFile)
' 아래는 동일한 결과는 가지는 Exec 를 통한 실행이다.
' 실행을 통해 반환되는 StdOut 에 접근하기위해 임시파일 만들고 할 필요가 없다.
Dim Shell : Set Shell = WScript.CreateObject("WScript.Shell")
Dim ExecObject : Set ExecObject = Shell.Exec ("cmd /c ping -n 3 -w 1000 157.59.0.1")
Do While Not ExecObject.StdOut.AtEndOfStream
strText = ExecObject.StdOut.ReadLine
Loop
- [Method] Sign, SignFile, Verify, VerifyFile
Sign
Signs a script stored in a string.
SignFile
Signs a script using a digital signature.
Verify
Verifies a digital signature retrieved as a string.
VerifyFile
Verifies the digital signature encapsulated in a script.
- [Method] CreateObject, GetObject
CreateObject
Creates an object specified by the strProgID parameter.
CreateScript
Creates a WshRemote object (an object that represents an instance of a script
running in a remote process).
CreateShortcut
Creates an object reference to a shortcut or URLshortcut.
ConnectObject
Connects an object's event sources to functions with a given prefix.
DisconnectObject
Disconnects a previously connected object from Windows Script Host.
GetObject
Retrieves an Automation object from a file or an object specified by the strProgID parameter.
[Method] MapNetworkDrive
MapNetworkDrive
Maps the share point specified by strRemoteName to the local resource name strLocalName.
EnumNetworkDrives
Returns the current network drive mappings.
EnumPrinterConnections
Returns the current network printer mappings.
RemoveNetworkDrive
Removes the current resource connection denoted by strName.
RemovePrinterConnection
Removes the current resource connection denoted by strName.
AddPrinterConnection
Adds a DOS-style printer connection to your computer.
AddWindowsPrinterConnection
Adds a Windows-style printer connection to your computer.
SetDefaultPrinter
Sets the default printer to the remote printer specified.
- [Method] ExpandEnvironmentStrings
* 환경변수값 알아내기 *
strReturn = WshShell.ExpandEnvironmentStrings(strString)
- strReturn : an environment variable's expanded value.
- strString : name of the environment variable.
- Remarks :
The ExpandEnvironmentStrings method expands environment variables
defined in the PROCESS environment space only.
'Visual Basic Script
Set WshShell = WScript.CreateObject("WScript.Shell")
WScript.Echo "WinDir is " & WshShell.ExpandEnvironmentStrings("%WinDir%")
//JScript
var WshShell = WScript.CreateObject("WScript.Shell");
WScript.Echo("WinDir is " + WshShell.ExpandEnvironmentStrings("%WinDir%"));
* ReNamer.vbs *
입력 1. 대상 폴더 경로의 마지막에 \ 가 있으면 파일명 변경, 없으면 폴더명 변경.
입력 2. 찾을 단어, 바꿀 단어 를 입력받는다.
- 쉼표로 구분
- 바꿀 단어는 공백이 올 수 있다( = 특정 문자 제거)
- 찾을 단어가 숫자 0 이라면 맨 앞 접두어 삽입으로 간주한다.
Option Explicit
'On Error Resume Next
'Err.Clear
Dim Shell : Set Shell = WScript.CreateObject("WScript.Shell")
Dim FSO : Set FSO = WScript.CreateObject("Scripting.FileSystemObject")
Dim TargetPath, fileMode
TargetPath = InputBox ("대상 폴더의 절대경로를 입력해 주세요." _
& vbCrLf & "마지막에 \가 있으면 파일명 변경, " _
& vbCrLf & "없으면 폴더명 변경입니다. " _
& vbCrLf & vbCrLf & "예) C:\Temp 또는 C:\Temp\", "Parent Path")
' InputBox 는 Popup 과는 달리 오브젝트(WshShell)없이 단독으로 사용 가능.
Call CheckNull(TargetPath)
TargetPath = Trim(TargetPath)
' 기본은 폴더명 변경 , 경로 마지막에 \ 가 있으면 파일명 변경
' \ 가 붙은 경우, 대상 폴더의 경로를 얻기 위해 마지막 \ 는 제거해 줘야 한다.
fileMode = False
If Right(TargetPath, 1) = "\" Then
TargetPath = Left(TargetPath, Len(TargetPath)-1) ' 마지막 \ 제거
fileMode = True
End If
Call CheckRoot(TargetPath)
If fileMode = True Then
Call RepFiles
Else
Call RepFolders
End If
'[함수화]*******************************
Sub CheckRoot(s)
If Trim(s) = "" Then ' 경로 입력 안했거나 취소버튼 누른 경우
WScript.Quit
ElseIf Len(s) <= 3 Then ' C C: C:\ 등의 경우
Shell.Popup "루터 디렉토리는 대상 폴더가 될 수 없습니다. ", 3, "Path Error", vbOkOnly
WScript.Quit
ElseIf Not FSO.FolderExists(s) Then
Shell.Popup "경로가 존재하지 않습니다. ", 3, "Path Error", vbOkOnly
WScript.Quit
End If
End Sub
Sub CheckNull(s)
If Trim(s) = "" Then
Shell.Popup " 입력값 없음 ", 1, "Input Empty", vbOkOnly
WScript.Quit
End If
End Sub
Sub CheckRest(s)
If InStr(1, s, ",", 1) <= 0 Then ' s 에서 쉼표가 위치한 곳(순서가 <= 0 는 말은 없다는 뜻)
Shell.Popup "찾을 단어와 바꿀 단어를 쉼표로 구분하여 입력해 주세요. ", 3, "Input Error", vbOkOnly
WScript.Quit
End If
End Sub
'[파일명 변경]***************************
Sub RepFiles
Dim inputStr : inputStr = InputBox ("* 파일명 변경 *" & vbCrLf _
& "찾을 단어와 바꿀 단어를 쉼표로 구분하여 입력해 주세요." & vbCrLf & vbCrLf _
& "교체) target words, new words" & vbCrLf _
& "삭제) target words," & vbCrLf _
& "접두어 삽입) 0, insert words", "파일명 변경")
Call CheckNull(inputStr)
Call CheckRest(inputStr)
Dim StrArray : StrArray = Split(inputStr, ",", -1, 1) ' 쉼표로 구분(배열을 생성)
Dim FindStr : FindStr = LTrim( StrArray(0) ) ' 단어 왼쪽 공백만 없앤다.
Call CheckNull(FindStr)
Dim RepStr : RepStr = LTrim( StrArray(1) ) ' 바꿀 단어는 Null Check 안함.
Dim objFold : Set objFold = FSO.GetFolder(TargetPath)
Dim fcoll : Set fcoll = objFold.Files
' Folder.files 와 Folder.subfolders는 콜렉션 객체를 생성한다.
Dim f1, oName, nName, oPath, nPath
For Each f1 in fcoll
oName = f1.name ' 하위 파일의 이름
If IsNumeric(FindStr) Then ' 찾을 문자가 숫자 0 이면 접두어 삽입 모드
nName = RepStr & oName
Else
nName = Replace(oName, FindStr, RepStr, 1, -1, 1)
End If
oPath = TargetPath & "\" & oName
nPath = TargetPath & "\" & nName
If Not FSO.FileExists(nPath) Then ' 같은 이름 있으면 변경 안함
FSO.MoveFile oPath, nPath
End If
Next
Set objFold = Nothing
Set fcoll = Nothing
End Sub
'[폴더명 변경]***************************
Sub RepFolders
Dim inputStr : inputStr = InputBox ("* 폴더명 변경 *" & vbCrLf _
& "찾을 단어와 바꿀 단어를 쉼표로 구분하여 입력해 주세요." & vbCrLf & vbCrLf _
& "교체) target words, new words" & vbCrLf _
& "삭제) target words," & vbCrLf _
& "접두어 삽입) 0, insert words", "폴더명 변경")
Call CheckNull(inputStr)
Call CheckRest(inputStr)
Dim StrArray : StrArray = Split(inputStr, ",", -1, 1) ' 쉼표로 구분(배열을 생성)
Dim FindStr : FindStr = LTrim( StrArray(0) ) ' 단어 왼쪽 공백만 없앤다.
Call CheckNull(FindStr)
Dim RepStr : RepStr = LTrim( StrArray(1) )
Dim objFold : Set objFold = FSO.GetFolder(TargetPath)
Dim dcoll : Set dcoll = objFold.SubFolders
Dim d1, oName, nName, oPath, nPath
For Each d1 in dcoll
oName = d1.name ' 하위 폴더의 이름
If IsNumeric(FindStr) Then
nName = RepStr & oName
Else
nName = Replace(oName, FindStr, RepStr, 1, -1, 1)
End If
oPath = TargetPath & "\" & oName
nPath = TargetPath & "\" & nName
If Not FSO.FolderExists(nPath) Then ' 같은 이름 있으면 변경 안함
FSO.MoveFolder oPath, nPath
End If
Next
Set objFold = Nothing
Set dcoll = Nothing
End Sub
Set Shell = Nothing
Set FSO = Nothing
WScript.Quit
WSH - ex) 코덱박사 슈퍼코덱팩 자동설치 | | |
* AutoInstall.vbs *
Option Explicit
On Error Resume Next
Err.Clear
Dim Shell : Set Shell = WScript.CreateObject("WScript.Shell")
Dim FSO : Set FSO = CreateObject("Scripting.FileSystemObject")
Dim COMSPEC : COMSPEC = Shell.ExpandEnvironmentStrings("%COMSPEC%")
Dim ExeFile : ExeFile = "Super_20060524.exe" ' 파일명 바꾸면 설치 에러남
If MsgBox ("코덱박사 슈퍼 코덱팩 v20060524 을 설치하시겠습니까? " , 36, "Setup - SuperCodec") = 6 Then
Shell.Run COMSPEC & " /c " & ExeFile & " & Exit", 0
'cmd창 숨기고 설치창 활성화. 뒤에 ,true 붙이면 안됨
Wscript.Sleep 3000
Shell.AppActivate "코덱박사 슈퍼 코덱팩 v20060524" '활성창 타이틀
Wscript.Sleep 800
Shell.SendKeys "~", True ' 엔터키
Wscript.Sleep 1000
Shell.SendKeys "~", True
Wscript.Sleep 1000
Shell.SendKeys "{TAB}", True
Wscript.Sleep 500
Shell.SendKeys "{right}", True
Wscript.Sleep 500
Shell.SendKeys "~", True
Wscript.Sleep 1000
Shell.SendKeys "~", True
Wscript.Sleep 1000
Shell.SendKeys "~", True
Wscript.Sleep 1000
Shell.SendKeys "{TAB}", True
Wscript.Sleep 500
Shell.SendKeys "{END}", True '맨아래칸 이동은 {down} 쓸 필요없이 바로 {END} 로..
Wscript.Sleep 1000
Shell.SendKeys " ", True ' PCClear는 설치요소에서 제거 ( " " -> 스페이스키)
Wscript.Sleep 1000
Shell.SendKeys "{TAB}", True
Wscript.Sleep 500
Shell.SendKeys "{right}", True
Wscript.Sleep 500
Shell.SendKeys "~", True
Wscript.Sleep 1000
Shell.SendKeys "~", True
Wscript.Sleep 1000
Shell.SendKeys "~", True
Wscript.Sleep 3000
Shell.SendKeys "~", True ' GomPlayer 발견 - 최적화할까요? => yes
' GomPlayer , KMPlayer 등 미디어재생 소프트웨어를 먼저 설치해야 한다.
Wscript.Sleep 3500
Shell.SendKeys "~", True ' nomal
Wscript.Sleep 1000
Shell.SendKeys "~", True ' 2 channel
Wscript.Sleep 1000
Shell.SendKeys "~", True ' 환경설정
' Call DelStartup() ' 한글Windows에서는 하면 안됨...
Else
Shell.Popup "코덱박사 슈퍼 코덱팩 v20060524 설치가 취소되었습니다. ", 3, "Cancle", 48
WScript.Quit
End if
' 영문Windows에는 "시작프로그램"이라는 폴더가 없다. ( Start Menu 가 있다 )
Sub DelStartup()
Dim KorStartMenu : KorStartMenu = Shell.SpecialFolders("Programs") & "\시작프로그램"
If FSO.FolderExists(KorStartMenu) Then
FSO.DeleteFolder KorStartMenu
End If
End Sub
Set Shell = Nothing
Set FSO = Nothing
WScript.Quit
-
* AutoInstall.vbs *
Option Explicit
On Error Resume Next
Err.Clear
Dim Shell : Set Shell = WScript.CreateObject("WScript.Shell")
Dim FSO : Set FSO = CreateObject("Scripting.FileSystemObject")
Dim WshEnv : Set WshEnv = Shell.Environment("Process")
Dim ProgramDir : ProgramDir = WshEnv("ProgramFiles")
Dim COMSPEC : COMSPEC = Shell.ExpandEnvironmentStrings("%comspec%")
' COMSPEC 지정할 필요없이 바로 Shell.Run "%comspec%~ 해도 됨..
Const ExeFile = "GOM.EXE" '고정된 이름은 변수가 아닌 상수로 지정해도 무방..
If MsgBox ("곰플레이어 1.9를 설치하시겠습니까? ", 36, "Setup - GomPlayer") = 6 Then
Shell.Run COMSPEC & " /c " & ExeFile & " & Exit", 0
' 0 => cmd창 숨기고 설치창 활성화. 뒤에 ,true 붙이면 안됨
Wscript.Sleep 3000
Shell.AppActivate "곰플레이어 설치"
Wscript.Sleep 800
Shell.SendKeys "~", True ' next [엔터]
Wscript.Sleep 800
Shell.SendKeys "~", True ' 동의
Wscript.Sleep 1000
Shell.SendKeys "{TAB}", True ' 구성요소 (모든 동영상 확장자 등록 체크)
Wscript.Sleep 500
Shell.SendKeys "{DOWN}", True
Wscript.Sleep 500
Shell.SendKeys "{DOWN}", True
Wscript.Sleep 500
Shell.SendKeys "{DOWN}", True
Wscript.Sleep 500
Shell.SendKeys " ", True
Wscript.Sleep 800
Shell.SendKeys "~", True
Wscript.Sleep 1000
Shell.SendKeys "{DEL}", True ' delete 키
Wscript.Sleep 800
Shell.SendKeys ProgramDir & "\GomPlayer", True ' 설치경로 변경( c:\prog~\Gomplayer )
Wscript.Sleep 800
Shell.SendKeys "~", True
Wscript.Sleep 6500
Shell.SendKeys "{TAB}", True
Wscript.Sleep 800
Shell.SendKeys "~" , True
Else
Shell.Popup "곰플레이어 설치가 취소되었습니다. ", 3, "Cancle", 48
WScript.Quit
End if
' 바로가기 폴더(아이팝) 지우고 GomPlayer 새로 생성
Dim Programs : Programs = Shell.SpecialFolders("Programs") ' or AllUsersPrograms
Dim OldShortDir : OldShortDir = Programs & "\아이팝 (www.ipop.co.kr)"
Dim NewShortDir : NewShortDir = Programs & "\GomPlayer"
FSO.DeleteFolder OldShortDir
FSO.CreateFolder NewShortDir
Dim ExeLink : Set ExeLink = Shell.CreateShortcut(NewShortDir & "\곰플레이어.lnk")
ExeLink.HotKey = "CTRL+SHIFT+G"
ExeLink.TargetPath = ProgramDir & "\GomPlayer\Gom.exe"
ExeLink.WorkingDirectory = ProgramDir & "\GomPlayer"
ExeLink.Save
Set ExeLink = Nothing
Dim ManLink : Set ManLink = Shell.CreateShortcut(NewShortDir & "\곰매니저.lnk")
ManLink.TargetPath = ProgramDir & "\GomPlayer\GomMgr.exe"
ManLink.WorkingDirectory = ProgramDir & "\GomPlayer"
ManLink.Save
Set ManLink = Nothing
Dim UnLink : Set UnLink = Shell.CreateShortcut(NewShortDir & "\곰플레이어 제거.lnk")
UnLink.TargetPath = ProgramDir & "\GomPlayer\Uninstall.exe"
UnLink.Save
Set UnLink = Nothing
' _ad_temp_.ini 파일이 을 읽기전용으로 속성 변경.
' 최초 실행 전이라면 _ad_temp_.ini 파일이 아직 생성되지 않았음.
' _ad_temp_.ini 파일이 없는 상태라면 Gom.exe 를 실행시키야 환경설정창이 뜬다.
Dim iniFile : iniFile = ProgramDir & "\GomPlayer\_ad_temp_.ini"
Dim WizFile
If FSO.FileExists(iniFile) Then
WizFile = "GomWiz.exe"
Else
WizFile = "Gom.exe"
End If
Dim WizExec : Set WizExec = Shell.Exec(ProgramDir & "\GomPlayer\" & WizFile)
Wscript.Sleep 1000
Shell.AppActivate "언어 선택"
Shell.SendKeys "~" , True
Wscript.Sleep 800
Shell.AppActivate "곰플레이어 환경 설정 길잡이"
Wscript.Sleep 800
Shell.SendKeys "~" , True ' 일반 모드
Wscript.Sleep 800
Shell.SendKeys "~" , True ' 자체 코덱, 2채널 스피커
Wscript.Sleep 800
Shell.SendKeys "~", True
Wscript.Sleep 800
Shell.SendKeys "~" , True
Wscript.Sleep 800
Shell.SendKeys " " , True ' 곰플레이어 실행 - 체크해제
Wscript.Sleep 800
Shell.SendKeys "~" , True
Wscript.Sleep 1500
Shell.SendKeys "{ESC}" , True ' 곰플레이어 끄기
' WizExec 작업이 완전히 끝나야 다음으로 넘어간다.
' Run 과 Exec 의 차이 : Exec는 결과가 오브젝트로 생성되므로 이걸 다시 이용할 수 있다.
Do While WizExec.Status <> 1
WScript.Sleep 100
Loop
Call SetReadOnly(iniFile)
Shell.Run "regedit /s config.reg"
'Shell.Popup "곰플레이어 1.9 설치가 완료되었습니다. ", 3
'_ad_temp_.ini 파일을 읽기전용으로..
Sub SetReadOnly(f)
Dim f1 : Set f1 = FSO.CreateTextFile(f, true) ' 덮어쓰면서 생성
Dim f2 : Set f2 = FSO.GetFile(f1)
f2.Attributes = 1
Set f1 = Nothing
Set f2 = Nothing
End Sub
Set Shell = Nothing
Set FSO = Nothing
Set WshEnv = Nothing
Set WizExec = Nothing
WScript.Quit
------------------------------
<config.reg>
Windows Registry Editor Version 5.00
; 옵션설정 - 업데이트 자동확인(x), 비슷한 파일명 열기(x), 재생시에만 맨위
[HKEY_CURRENT_USER\Software\GRETECH\GomPlayer\OPTION]
"bActiveMsg"=dword:00000000
"bCheckUpdate"=dword:00000000
"bNotifyUpdate"=dword:00000000
"bNotifyMinorUpdate"=dword:00000000
"bNotifySimilarFile"=dword:00000000
"idMenuLang"=dword:00000412
"idAudioLang"=dword:00000412
"idSubtitlesLang"=dword:00000412
"nOnTopMode"=dword:00000002
cf, 곰플레이어 2.0 버전 이상은 자동설치시 픽~ (Kill Processor).