cmd設置環境變量能夠方便咱們bat腳本的運行,可是要注意的是變量只在當前的cmd窗口有做用(局部生效),若是想要設置持久的環境變量須要咱們經過兩種手段進行設置:一種是直接修改註冊表,另外一種是經過個人電腦-〉屬性-〉高級,來設置系統的環境變量。 html
1、查看當前全部可用的環境變量:輸入 set 便可查看。 java
2、查看某個環境變量:輸入 "set 變量名"便可,好比想查看temp變量的值,即輸入 set temp windows
固然也可使用echo %temp% 網絡
3、修改環境變量 :輸入 "set 變量名=變量內容"便可,好比將temp設置爲"d:\tempfile",只要輸入set temp="d:\tempfile"。注意,此修改環境變量是指用如今的內容去覆蓋之前的內容,並非追加。好比當我設置了上面的path路徑以後,若是我再從新輸入set temp="c",再次查看temp路徑的時候,其值爲"c",而不是"d:\tempfile";"c"。 app
4、設置爲空:若是想將某一變量設置爲空,輸入"set 變量名="便可。如"set path=" 那麼查看path的時候就爲空。注意,上面已經說了,只在當前命令行窗口起做用。所以查看path的時候不要去右擊"個人電腦"——"屬性"........ less
5、給變量追加內容(不一樣於3,那個是覆蓋):輸入"set 變量名=%變量名%;變量內容"。如,爲temp添加一個新的路徑,輸入" set path=%path%;d:\tempfile"便可將d:\tempfile添加到path中,再次執行"set path=%path%;c:",那麼,使用set path語句來查看的時候,將會有:d:\tempfile;c:,而不是像第3步中的只有c:。 dom
環境變量詳細解釋 ide
1、查看當前可用的全部環境變量(=系統變量+用戶變量) 函數
set 工具
查看某個環境變量,如PATH
set PATH
添加環境變量,如xxx=aa
set xxx=aa
將環境變量(如xxx)的值置爲空
set xxx=
在某個環境變量(如PATH)後添加新的值(如d:\xxx)
set PATH=%PATH%;d:\xxx
[注]:以命令行方式對環境變量的操做只對當前窗口的應用有效!
2、Windows下JAVA用到的環境變量主要有3個:JAVA_HOME、CLASSPATH、PATH。
1)JAVA_HOME指向的是JDK的安裝路徑,如x:\ j2sdk1.4.2,在這路徑下你應該可以找到bin、lib等目錄。設置方法:JAVA_HOME=c:\ j2sdk1.4.2
2)PATH變量的做用
java程序在運行時首先在path變量所定義的路徑去找java.exe,並以最早找到的爲準,若是安裝完j2sdk後不加設置,通常是C:\WINDOWS\system32目錄。
j2sdk1.4(還有其它java開發工具如jbuilder8)在安裝後會將java.exe拷貝到C:\WINDOWS\system32目錄下,當執行java.exe時,須要裝載這個SDK下的一些文件。
如j2sdk1.4在安裝完成後,C:\WINDOWS\system32下的java.exe在運行時會在C:\Program File\java\目錄下裝載必需的一些文件。但安裝j2sdk後通常會在PATH變量的最前面設置C:\ j2sdk1.4.2 \bin。
當先安裝j2sdk1.4.2,後安裝jbuilder8等開發工具時,因爲jbuilder8的java.exe在拷貝到C:\WINDOWS\system32時可能覆蓋了j2sdk1.4.2的java.exe,那麼這時在運行的java.exe會到jbuilder8所在的目錄去裝載必需的一些文件。
3)CLASSPATH環境變量的做用
告訴類裝載器到哪裏去尋找第三方提供的類和用戶定義的類。也可用使用JVM命令行參數-classpath分別爲應用程序指定類路徑,在-classpath中指定的類路徑覆蓋CLASSPATH環境變量中指定的值。
3、當機器內裝有多個SDK版本時,如何查看所用的是哪一個SDK?
java -verbose
在出現的屏幕信息中能夠看出系統裝載的是哪一個目錄下的文件。
4、Windows OS下設置PATH的方法
〔系統〕->〔環境〕-> 〔高級〕,在PATH變量的文本框中的最前面輸入C:\ j2sdk1.4.2\bin
或在命令行窗口中執行 set path=c:\j2sdk1.4.2\bin;%path%; 這樣在命令行窗口的任一路徑下均可以執行java.exe程序了。或設置PATH=%JAVA_HOME%\bin;%PATH%
5、對於CLASSPATH環境變量的設置方法要加倍當心,是由於之後你出現的莫名其妙80%以上的怪問題均可能是因爲CLASSPATH設置不對引發的。
CLASSPATH=.\;%JAVA_HOME%\lib\tools.jar
首先要注意的是最前面的".\;",——句點反斜槓分號。這個是告訴JDK,搜索CLASS時先查找當前目錄的CLASS文件。
【Troubleshooting】
編譯會出現如下狀況,看你是否真得都理解環境變量的設置,並能解決它。
[T1]error:java不是一個可運行的程序? 因爲沒有設置環境變量path
[T2] error:不能打開某個目錄? 多是忽視了path環境變量中的目錄的設置順序。
[T3]Exception on thread "main" java.lang.DoClassDefFoundError:Test? 沒有設置classpath的路徑。
cmd查看環境變量
1、查看當前全部可用的環境變量:輸入 set 便可查看。
2、查看某個環境變量:輸入 "set 變量名"便可,好比想查看path變量的值,即輸入 set path
3、修改環境變量 :輸入 "set 變量名=變量內容"便可,好比將path設置爲"d:\hacker.exe",只要輸入set path="d:\nmake.exe"。注意,此修改環境變量是指用如今的內容去覆蓋之前的內容,並非追加。好比當我設置了上面的path路徑以後,若是我再從新輸入set path="c",再次查看path路徑的時候,其值爲"c:",而不是"d:\nmake.exe";"c"。
4、設置爲空:若是想將某一變量設置爲空,輸入"set 變量名="便可。如"set path=" 那麼查看path的時候就爲空。注意,上面已經說了,只在當前命令行窗口起做用。所以查看path的時候不要去右擊"個人電腦"——"屬性"........
5、給變量追加內容(不一樣於3,那個是覆蓋):輸入"set 變量名=%變量名%;變量內容"。如,爲path添加一個新的路徑,輸入" set path=%path%;d:\hacker.exe"便可將d:\hacker.exe添加到path中,再次執行"set path=%path%;c:",那麼,使用set path語句來查看的時候,將會有:d:\hacker.exe;c:,而不是像第3步中的只有c:。
%ALLUSERSPROFILE% 局部 返回全部"用戶配置文件"的位置。
%APPDATA% 局部 返回默認狀況下應用程序存儲數據的位置。
%CD% 局部 返回當前目錄字符串。
%CMDCMDLINE% 局部 返回用來啓動當前的 Cmd.exe 的準確命令行。
%CMDEXTVERSION% 系統 返回當前的"命令處理程序擴展"的版本號。
%COMPUTERNAME% 系統 返回計算機的名稱。
%COMSPEC% 系統 返回命令行解釋器可執行程序的準確路徑。
%DATE% 系統 返回當前日期。使用與 date /t 命令相同的格式。由 Cmd.exe 生成。有關 date 命令的詳細信息,請參閱 Date。
%ERRORLEVEL% 系統 返回最近使用過的命令的錯誤代碼。一般用非零值表示錯誤。
%HOMEDRIVE% 系統 返回鏈接到用戶主目錄的本地工做站驅動器號。基於主目錄值的設置。用戶主目錄是在"本地用戶和組"中指定的。
%HOMEPATH% 系統 返回用戶主目錄的完整路徑。基於主目錄值的設置。用戶主目錄是在"本地用戶和組"中指定的。
%HOMESHARE% 系統 返回用戶的共享主目錄的網絡路徑。基於主目錄值的設置。用戶主目錄是在"本地用戶和組"中指定的。
%LOGONSEVER% 局部 返回驗證當前登陸會話的域控制器的名稱。
%NUMBER_OF_PROCESSORS% 系統 指定安裝在計算機上的處理器的數目。
%OS% 系統 返回操做系統的名稱。Windows 2000 將操做系統顯示爲 Windows_NT。
%PATH% 系統 指定可執行文件的搜索路徑。
%PATHEXT% 系統 返回操做系統認爲可執行的文件擴展名的列表。
%PROCESSOR_ARCHITECTURE% 系統 返回處理器的芯片體系結構。值: x86,IA64。
%PROCESSOR_IDENTFIER% 系統 返回處理器說明。
%PROCESSOR_LEVEL% 系統 返回計算機上安裝的處理器的型號。
%PROCESSOR_REVISION% 系統 返回處理器修訂號的系統變量。
%PROMPT% 局部 返回當前解釋程序的命令提示符設置。由 Cmd.exe 生成。
%RANDOM% 系統 返回 0 到 32767 之間的任意十進制數字。由 Cmd.exe 生成。
%SYSTEMDRIVE% 系統 返回包含 Windows XP 根目錄(即系統根目錄)的驅動器。
%SYSTEMROOT% 系統 返回 Windows XP 根目錄的位置。
%TEMP% and %TMP% 系統和用戶 返回對當前登陸用戶可用的應用程序所使用的默認臨時目錄。有些應用程序須要 TEMP,而其它應用程序則須要 TMP。
%TIME% 系統 返回當前時間。使用與 time /t 命令相同的格式。由 Cmd.exe 生成。有關 time 命令的詳細信息,請參閱 Time。
%USERDOMAIN% 局部 返回包含用戶賬戶的域的名稱。
%USERNAME% 局部 返回當前登陸的用戶的名稱。
%UserProfile% 局部 返回當前用戶的配置文件的位置。
%WINDIR% 系統 返回操做系統目錄的位置。
開始與終止批處理文件中環境改動的本地化操做。在執行 Setlocal 以後所作的環境改動只限於批處理文件。要還原原先的設置,必須執行 Endlocal。達到批處理文件結尾時,對於該批處理文件的每一個還沒有執行的 Setlocal 命令,都會有一個隱含的 Endlocal 被執行。Endlocal結束批處理文件中環境改動的本地化操做。在執行Endlocal 以後所作的環境改動再也不僅限於批處理文件。批處理文件結束後,原先的設置沒法還原。
語法:
Setlocal {enableextension | disableextensions} {enabledelayedexpansion | disabledelayedexpansion}
...
Endlocal
...
若是命令擴展名被啓用,SETLOCAL 能夠接受{}中的可選參數,啓動或停用命令處理器擴展名及延緩環境變量擴展名。詳細信息,請參閱 CMD /? 和 SET /? 。
不管在 Setlocal 命令以前它們的設置是什麼,這些修改會一直保留到匹配的 Endlocal 命令。
示例:
@ECHO OFF
Echo Before Setlocal:
Set PATH
Pause
Setlocal
Rem reset environment var PATH
Set PATH=E:\TOOLS
Echo after Setlocal and reset PATH
Set PATH
Pause
Endlocal
Echo Recovery PATH by Endlocal
Set PATH
從上例咱們能夠看到環境變量PATH第1次被顯示得時候是系統默認路徑。被設置成了"E:\TOOLS"後顯示爲"E:\TOOLS"。但當 Endlocal 後咱們能夠看到他又被還原成了系統的默認路徑。但這個設置只在該批處理運行的時候有做用。當批處理運行完成後環境變量PATH將會還原。
技巧:
若是有一個參數,SETLOCAL 命令將設置 ERRORLEVEL 的值。若是有兩個有效參數中的一個,該值則爲零。用下列技巧,您能夠在批腳本中使用這個來決定擴展名是否可用:
VERIFY OTHER 2>nul
SETLOCAL ENABLEEXTENSIONS
IF ERRORLEVEL 1 echo Unable to enable extensions
這個方法之因此有效,是由於在 CMD.EXE 的舊版本上,SETLOCAL不設置 ERRORLEVEL 值。具備不正確參數的 VERIFY 命令將ERRORLEVEL 值初始化成非零值。
系統環境變量: |
VBScript Code:
複製代碼代碼以下:
' Create a WSH Shell object:
Set wshShell = CreateObject( "WScript.Shell" )
'
' Create a new key:
wshShell.RegWrite "HKCU\TestKey\", ""
' Create a new DWORD value:
wshShell.RegWrite "HKCU\TestKey\DWordTestValue", 1, "REG_DWORD"
' Create a new subkey and a string value in that new subkey:
wshShell.RegWrite "HKCU\TestKey\SubKey\StringTestValue", "Test", "REG_SZ"
' Read the values we just created:
WScript.Echo "HKCU\TestKey\DWordTestValue = " _
& wshShell.RegRead( "HKCU\TestKey\DWordTestValue" )
WScript.Echo "HKCU\TestKey\SubKey\StringTestValue = """ _
& wshShell.RegRead( "HKCU\TestKey\SubKey\StringTestValue" ) & """"
' Delete the subkey and key and the values they contain:
wshShell.RegDelete "HKCU\TestKey\SubKey\"
wshShell.RegDelete "HKCU\TestKey\"
' Note: Since the WSH Shell has no Enumeration functionality, you cannot
' use the WSH Shell object to delete an entire "tree" unless you
' know the exact name of every subkey.
' If you don't, use the WMI StdRegProv instead.
' Release the object
Set wshShell = Nothing
用VBScript編寫的WSH程序文件的擴展名爲.vbs,該腳本程序在窗口界面是由wscript.exe文件解釋執行的,在字符界面是由cscript.exe文件解釋執行的,命令格式爲:cscript filename.vbs
建立對象
用VBScript修改註冊表,必須先建立一個能於操做系統溝通的對象,再利用該對象的各類方法對註冊表進行操做,建立這個對象的方法和格式以下:
Dim OperationReGIStry
Set OperationRegistry=WScript.CreateObject("WScript.Shell")
上述這些代碼就建立了一個能與操做系統溝通的對象OperationRegistry
對象的方法
有了以上這個對象,並不等於就能立刻對註冊表進行操做,咱們還必須弄清該對象對註冊表進行操做的幾種重要方法.
1.對註冊表的讀操做RegRead
2.對註冊表的寫操做RegWrite
3.對註冊表的刪操做RegDelete
補充一點,WSH還有兩個通用的方法:
WScript.Echo()用來顯示一串文本信息,至關於VB中的MsgBox()。
Wscript.Quit()用來退出VBScript程序。
方法的參數
對於以上三種操做RegRead,RegWrite,RegDelete都須要帶參數進行,而且這些操做的參數的個數和形式又不盡相同,下面我就把它們的一個共同且必不可少的參數講一下:
該參數可稱做是"路徑參數",它包括根鍵,主鍵路徑和鍵值,各部分表示的方法以下:
根鍵:
根鍵有兩種表示方法。
方法一:直接用它在註冊表中的字符串來表示,如:
HKEY_CLASSES_ROOT,HKEY_CURRENT_USER等
方法二:用縮寫的四個字母來表示,前兩個爲HK,後兩個即爲根鍵單詞的首字母。如:
根鍵HKEY_CLASSES_ROOT表示爲:HKCR, 根鍵HKEY_CURRENT_USER可表示爲:HKCU等。
主鍵路徑:
主鍵路徑就是目標鍵在註冊表中的主鍵位置,各個主鍵之間用"\"符分隔開。如:"Software\Microsoft\Windows\CurrentVersion\Policies\"
鍵值:
鍵值參數直接接在主鍵路徑以後。例如一個完整的路徑以下所示:
"HKCR\Software\Microsoft\Windows\CurrentVersion\Policies\NoRun"
方法詳解
1、RegRead操做詳解
讀操做RegRead主要是用來讀取註冊表中主鍵的默認值或鍵值的數據,咱們能夠將讀得的數據送到相應的變量中,再利用VB中的MsgBox()函數將該數據顯示出來,這就達到了讀取註冊表中數據的目的(也能夠利用對象OperationRegistry的方法Popup()將讀取的數據送至屏幕), 例如:
複製代碼代碼以下:
'read.vbs(將如下代碼存爲read.vbs文件)
Dim OperationRegistry
Set OperationRegistry=WScript.CreateObject("WScript.Shell")
Dim Read_Data1,Read_Data2
Read_Data1=OperationRegistry.RegRead("HKCR\.xxf\")
'讀取根鍵HKEY_CLASSES_ROOT之下的.xxf主鍵的默認值,並將該數據送至變量Read_Data1
Read_Data2=OperationRegistry.RegRead("HKCR\.xxf\value")
'讀取.xxf主鍵之下的value鍵值的數據,並將該數據送至變量Read_Data2
MsgBox("Default="&Read_Data1&" value="&Read_Data2)
'將讀取的數據顯示出來
2、RegWrite操做詳解
寫操做RegWrite主要是用來在註冊表中新建主鍵或鍵值,並要賦予給它們一個初始值,該操做一樣能夠對註冊表中以存在的主鍵或鍵值進行數據的修改,所以寫操做的參數結構就比讀操做要複雜一些,它不只要路徑參數,還要一個初始值和類型參數.
先來看初始值參數,該參數對於寫操做來講是必不可少的,它能夠爲空(null)但卻不能省掉。在新建主鍵時,初始值參數就賦給了該主鍵的默認值,在新建鍵值時,初始值參數就成了新建鍵值的初始數據.而初始值的類型,則是由類型參數決定的.類型主要有如下三種:
(1)REG_SZ:字符型.該類型爲缺省類型
(2)REG_DWORD:雙字節型.
(3)REG_BINARY:二進制型.
以上三種類型第1種和第2種用得最多,第3種類型在某些場合能夠用第2種加以替代,這三種類型的賦值方法以下:
對於REG_SZ型:直接用字符串賦予,如"text","string"等
對於REG_DWORD型和REG_BINARY型則有兩種賦值方式
i)直接用十進制的數表示,如:0,1等.
ii)用十六進制的數表示,如:0x12,0xff等. 看例:
複製代碼代碼以下:
'write.VBs
Dim OperationReGIStry
Set OperationRegistry=WScript.CreateObject("WScript.Shell")
Default=OperationRegistry.RegRead("HKCR\")
'獲取一個空值 (null)
OperationRegistry.RegWrite "HKCR\.xxf\",Default
'在根鍵HKEY_CLASSES_ROOT之下新建主鍵.xxf,並置其默認值爲空
OperationRegistry.RegWrite "HKCR\.xxf\","xxffile"
'在根鍵HKEY_CLASSES_ROOT之下新建主鍵.xxf,並置其默認值?quot;xxffile"
OperationRegistry.RegWrite "HKCR\.xxf\value1","string"
'在主鍵.xxf之下新建一個字符串型鍵值value1,並置其初始值爲"string"
OperationRegistry.RegWrite "HKCR\.xxf\value2",1,"REG_DWORD"
'在主鍵.xxf之下新建一個REG_DWORD型鍵值value2,並置其初始值爲1
OperationRegistry.RegWrite "HKCR\.xxf\value3",0Xff,"REG_BINARY"
'在主鍵.xxf之下新建一個二進制型鍵值value3,並置其初始值爲十六進制的ff
3、RegDelete操做詳解
刪除操做RegDelete主要是用來刪除註冊表中已存在的主鍵或鍵值,該操做是一種極其危險的操做,它能將主鍵或鍵值絕不留情的在註冊表中"砍掉",不管該鍵值下面有多重要的數據,它都能暢行無阻,所以在使用該操做時務必當心。
刪除操做的參數形式與讀操做的參數形式幾乎徹底相同,只是有一點小小的區別,那就是刪除操做不須要將操做的返回值送給某一變量,例如:
複製代碼代碼以下:
'delete.vbs
Dim OperationRegistry
Set OperationRegistry=WScript.CreateObject("WScript.Shell")
OperationRegistry.RegRead("HKCR\.xxf\value")
'刪除.xxf主鍵之下的value鍵值
OperationRegistry.RegRead("HKCR\.xxf\")
'刪除根鍵HKEY_CLASSES_ROOT之下的.xxf主鍵
強調一點,不要更改註冊表中已存在的主鍵或鍵值,更不要將它們刪除,由於對註冊表進行了不當的寫操做或刪操做,狀況嚴重的會致使系統崩潰!若是你真想這麼作,那就請你做好註冊表的備份。
應用實例
1、讀本機"計算機名"
複製代碼代碼以下:
'ReadComputerName.vbs
Dim ReadComputerName
Set ReadComputerName=WScript.CreateObject("WScript.Shell")
Dim ComputerName,RegPath
RegPath="HKLM\System\CurrentControlSet\Control\
ComputerName\ComputerName\ComputerName"
ComputerName=ReadComputerName.RegRead(RegPath)
MsgBox("計算機名爲"&ComputerName)
2、隱藏快捷方式圖標上的小箭頭
複製代碼代碼以下:
'Hidden.vbs
Dim HiddenArrowIcon
Set HiddenArrowIcon=WScript.CreateObject("WScript.Shell")
Dim RegPath1,RegPath2
RegPath1="HKCR\lnkfile\IsShortCut"
RegPath2="HKCR\piffile\IsShortCut"
HiddenArrowIcon.RegDelete(RegPath1)
HiddenArrowIcon.RegDelete(RegPath2)
3、改造"開始"菜單
複製代碼代碼以下:
'ChangeStartMenu.vbs
Dim ChangeStartMenu
Set ChangeStartMenu=WScript.CreateObject("WScript.Shell")
RegPath="HKCR\Software\Microsoft\Windows\CurrentVersion\Policies\"
Type_Name="REG_DWORD"
Key_Data=1
StartMenu_Run="NoRun"
StartMenu_Find="NoFind"
StartMenu_Close="NoClose"
Sub Change(Argument)
ChangeStartMenu.RegWrite RegPath&Argument,Key_Data,Type_Name
MsgBox("Success!")
End Sub
Call Change(StartMenu_Run) '禁用"開始"菜單中的"運行"功能
Call Change(StartMenu_Find) '禁用"開始"菜單中的"查找"功能
Call Change(StartMenu_Close) '禁用"開始"菜單中的"關閉系統"功能
4、向Windows中添加自啓動程序
該程序能在開機時自動運行。
複製代碼代碼以下:
'AddAutoRunProgram.vbs
'假設該程序在c:\myfile文件夾中,文件名爲autorun.exe
Dim AutoRunProgram
Set AutoRunProgram=WScript.CreateObject("WScript.Shell")
RegPath="HKLM\Software\Microsoft\Windows\CurrentVersion\Run\"
Type_Name="REG_SZ"
Key_Name="AutoRun"
Key_Data="C:\Myfile\autorun.exe"
'該自啓動程序的全路徑文件名
AutoRunProgram.Write RegPath&Key_Name,Key_Data,Type_Name
'在啓動組中添加自啓動程序autorun.exe
MsgBox("Success!")
chr(9) tab空格 chr(10) 換行 chr(13) 回車 Chr(13)&chr(10) 回車換行 chr(32) 空格符 chr(34) 雙引號 chr(39) 單引號
chr(33) ! chr(34) " chr(35) # chr(36) $ chr(37) % chr(38) & chr(39) ' chr(40) ( chr(41) ) chr(42) * chr(43) + chr(44) , chr(45) - chr(46) . chr(47) /
Chr(48) 0 Chr(49) 1 Chr(50) 2 Chr(51) 3 Chr(52) 4 Chr(53) 5 Chr(54) 6 Chr(55) 7 Chr(56) 8 Chr(57) 9
chr(58) chr(59) ; chr(60) < chr(61) = chr(62) > chr(63) ? chr(64) @
chr(65) A chr(66) B chr(67) C chr(68) D chr(69) E chr(70) F chr(71) G chr(72) H chr(73) I chr(74) J chr(75) K chr(76) L chr(77) M chr(78) N chr(79) O chr(80) P chr(81) Q chr(82) R chr(83) S chr(84) T chr(85) U chr(86) V chr(87) W chr(88) X chr(89) Y chr(90) Z
chr(91) [ chr(92) \ chr(93) ] chr(94) ^ chr(95) _ chr(96) `
chr(97) a chr(98) b chr(99) c chr(100) d chr(101) e chr(102) f chr(103) g chr(104) h chr(105) i chr(106) j chr(107) k chr(108) l chr(109) m chr(110) n chr(111) o chr(112) p chr(113) q chr(114) r chr(115) s chr(116) t chr(117) u chr(118) v chr(119) w chr(120) x chr(121) y chr(122) z
chr(123) { chr(124) | chr(125) } chr(126) ~ chr(127) chr(128) chr(153)™ chr(169) © chr(174) ® |
格式1:Windows 95/98/ME/NT 4.0第一行必須是"REGEDIT4"。而到了Windows 2000/XP/2003/Vista等windows操做系統則必需要是"Windows Registry Editor Version 5.00"。 2:第一行後必須空一行。條與條之間最好也空一行。每行前不能留空格。 3:註冊表信息頭尾用"["與"]"包起來; 4:" "內就是字符串內容;"DWORD"爲"0"就是用"dword:00000000"表示,反之是"1"則用dword:00000001來表示。 5:若是有兩個以上的註冊表信息,信息與信息之間就須要有空行隔開。 6:若是要刪除某個註冊表信息該怎麼辦?很簡單,在註冊表信息前面加上"-"(減)號 |
概要重要:此部分、 方法或任務包含一些介紹如何修改註冊表的步驟。可是,若是不正確地修改了註冊表,可能會出現嚴重的問題。所以,請確保仔細按照下列步驟操做。爲增長保護,對其進行修改以前備份註冊表。而後,您能夠在出現問題時還原註冊表。有關如何備份和還原註冊表的詳細信息,請單擊下面的文章編號,以查看 Microsoft 知識庫中相應的文章: 本分步指南介紹如何添加、 修改或刪除註冊表子項和值,經過使用註冊項 (.reg) 文件。Regedit.exe 使用.reg 文件來導入和導出註冊表子項和值。這些.reg 文件可用於遠程分發到多臺基於 Windows 的計算機的註冊表更改。當您運行.reg 文件時,該文件的內容合併到本地註冊表中。所以,分發.reg 文件時必須謹慎。 .Reg 文件的語法以下 ︰ [HKEY_LOCAL_ MACHINE\SOFTWARE\Policies\Microsoft\Windows\System] .Reg 文件能夠包含多個註冊表路徑。若是註冊表中不存在路徑語句中的層次結構的底部,將建立一個新子項。註冊表文件的內容發送到註冊表中輸入它們的順序。所以,若是您想要建立一個新子項與它下面的其餘子項,則必須按正確的順序輸入行。
有關注冊表數據類型的詳細信息,請單擊下面的文章編號,以查看 Microsoft 知識庫中相應的文章: DataValuex當即跟隨冒號 (或等號後 REG_SZ),而且必須是以適當的格式 (例如,字符串或十六進制)。對二進制數據項使用十六進制格式。 |
The AddForcedVirtualLoadPath(Path) function instructs ThinApp to load all DLLs from the specified path as virtual DLLs even if they are not located in the package. Use this function if the application needs to load external DLLs that depend on DLLs located inside the package. You can use the ForcedVirtualLoadPaths parameter in the Package.ini file to achieve the same result as this API function. For more information about "ForcedVirtualLoadPaths" see ThinApp Package.ini Parameters Reference Guide. [in] The filename or path for DLLs to load as virtual. You can load any DLL located in the same directory as the executable file as a virtual DLL. Origin = GetEnvironmentVariable("TS_ORIGIN") TS_ORIGIN is the path from which the executable file is running. You can delete the filename from TS_ORIGIN by finding the last backslash and removing all of the characters that follow it. LastSlash = InStrRev(Origin, "\") SourcePath = Left(Origin, LastSlash) You can instruct ThinApp to load all DLLs in the same or lower directory from where the source executable file resides. AddForcedVirtualLoadPath(SourcePath) This process enables you to drop additional files in the SourcePath tree and have them resolve import operations against virtual DLLs. |
Checking ThinApp Installation Files The ThinApp installation generates the VMware ThinApp directory in C:\Program Files\VMware. You might check the files in this directory to perform operations such as starting the Log Monitor utility to view recent activity. The following key files in the VMware ThinApp directory affect ThinApp operations:
ThinApp starts this utility during the setup capture process.
The snapshot.exe file references the snapshot.ini file. Advanced users might modify the snapshot.ini file to ensure that ThinApp does not capture certain entries when creating an application package. You can customize this template to ensure that the .msi files generated by ThinApp adhere to company deployment procedures and standards. For example, you can add registry settings that you want ThinApp to add to client computers as part of the installation. This registration includes setting up shortcuts and the Start menu and setting up file type associations that allow you to open applications.
|
You can adjust project files and build the application for deployment. Build virtual applications in the Setup Capture wizard
You can build the package at a later time with the build.bat file in the virtual application folder. For example, a Firefox 2.0.0.3 path to the build.bat file might be C:\Program Files\VMware\VMware ThinApp\Captures\Mozilla Firefox 2.0.0.3\build.bat.
You can rebuild the package at any time after you click Finish to make changes. |
Predefined Environment Variables The values for PackageIniOverrideFile (global and per application), ProjectPostProcessingCommand (global and per application), and InstallationCommand can contain environment variables. ThinApp Converter expands the value before using it. ThinApp Converter adds these variables as predefined environment variables:
Following is an example of how predefined variables can be used in the PackageIniOverrideFile, ProjectPostProcessingCommand, and InstallationCommand parameters. PackageIniOverrideFile=%AppInstallersRootDir%\AppSyncSettings.ini ;will resolve to \\AppInstallerServer\AppInstaller\AppSyncSettings.ini InstallationCommand=AdbeRdr920_en_US.exe /sAll PackageIniOverrideFile=%AppInstallerDir%\override.ini ;will resolve to \\AppInstallerServer\AppInstaller\Adobe\AppSyncSettings.ini |
Preparing the Configuration File for ThinApp Converter A sample configuration file, ThinAppConverter.ini, is included in the ThinApp installation. The file is generally located in C:\Program Files\VMware\VMware ThinApp. Modify or create a copy of this file to suit your requirements. Use UTF-8 encoding when you specify parameter values. The ThinAppConverter.ini configuration file includes the following section headings:
The HostEnvironment section of the configuration file contains the connection parameters for connecting to VMware ESX Server, VMware vCenter Server, or VMware Workstation on a local machine. [HostEnvironment] parameters are mandatory.
The name of the virtual machine to which ThinApp Converter is to connect.
The following example shows a virtual machine specified by ESX server hostname. VirtualMachineHost=MyEsx.vmware.com The following example shows a virtual machine specified by IP address. VirtualMachineHost=10.13.11.23 The following example shows a local machine specified as localhost. The login user name for the host machine. Use the same login user name for connecting to the server as you use for logging in to the VMware vSphere Client. You must have sufficient privileges to turn on and off virtual machines, take virtual machine snapshots, and so on. You can use UPN format when you specify a user name for vCenter. For example, user@domain.com. HostLoginUserName is ignored when logging into VMware Workstation. HostLoginPassword or HostLoginPasswordBase64 The login password for the host machine. You have the following options when you specify passwords:
All passwords are handled in the same way. Specifies that the user be prompted to enter a password. If you do not want to store the vSphere Server password in the configuration file, specify the value as true. When set to true, a prompt always appears, even if a HostLoginPassword is specified in the configuration file. The following example shows a typical host environment specification. The virtual machine name is specified as the ESX server hostname. A password has been specified, however the user will still be prompted to enter as password, as specified in HostLoginPasswordPrompt. VirtualMachineHost=MyEsx.vmware.com The VirtualMachineN section of the configuration file contains a list of the Windows-based virtual machines that will be utilized in the conversion process. Create a VirtualMachineX section for each virtual machine that you want to include, and specify their parameters. X is 1, and subsequent virtual machine sections are numbered sequentially. [VirtualMachine N ] parameters are mandatory. Specify the configuration path of the virtual machine. For ESX Server or vCenter Server, you can identify the virtual machine configuration file path using the vSphere Client. Identify the virtual machine configuration path using the vSphere Client
For Workstation, specify the entire file path on the host on which the VMX configuration file resides. For example, C:\MyVMs\Windows XP\WindowsXP.vmx. Do not place the path in quotation marks, even if the path contains a space. A valid user name for the virtual machine guest operating system. The user must have administrator privileges for the virtual machine guest operating system. You can use UPN format when you specify a user name. For example, user@domain.com. A valid password for the virtual machine guest operating system. You have the following options when you specify passwords: Specifying an encoded password does not increase security strength. You need to protect the actual INI file. All passwords are handled in the same way. If the Password setting is not used, the password for the guest is assumed to be blank. Most Windows virtual machines do not support automation with empty passwords, so you should specify a guest password. Specifies that the user be prompted to enter a password. If you do not want to store the virtual machine password in the configuration file, specify the value as true. When set to true, a prompt always appears, even if a password is specified in the configuration file. Following is an example for an ESX server-based environment. A password has been specified and, as PasswordPrompt is set to false, the user will not be prompted to enter a password. VmxPath=[Storage] WinXP_Converter/WinXP_Converter.vmx Following is an example for a VMware Workstation-based virtual machine. On virtual machine 1, PasswordPrompt has been set to true. The user will be prompted for a password even though a password has been specified in the configuration. VmxPath=C:\MyVMs\Windows XP\Windows XP.vmx VmxPath=C:\MyVMs\Windows 7\Windows 7.vmx UserName=adminuser@mydomain.com The Settings section of the configuration file contains the parameters for the application installation directory and ThinApp project output directory, in the form of UNC. It also contains several parameters controlling the conversion process behavior. ThinApp Converter only requires read-only permissions for the network share that contains the application installers. It requires read/write permissions for the network share that contains the ThinApp projects. If input and output directories are on the same file server, you must use the same user account to connect them. Specify the network share UNC path for the application installers. For example: \\fileserver\sharename, or \\fileserver\sharename\dirname. Specify the user name used for connecting to that network share. UPN format can be used when you specify a domain user, for example user@domain.com InputMountPassword or InputMountPasswordBase64 Specify the password for connecting to the network share. You have the following options when you specify passwords: Specifies that the user be prompted to enter a password. If you do not want to store the network share password in the configuration file, specify the value as true. When set to true, a prompt always appears, even if a password is specified in the configuration file. Specify the network share UNC path to the location of the generated ThinApp projects. For example: \\fileserver\sharename, or \\fileserver\sharename\dirname Specify the user name used for connecting to the OutputUncPath network share. UPN format can be used to specify a domain user, for example, user@domain.com. OutputMountPassword or OutputMountPasswordBase64 Specify the password for connecting to the network share. You have the following options when you specify passwords: Specifies that the user be prompted to enter a password. If you do not want to store the network share password in the configuration file, specify the value as true. When set to true, a prompt always appears, even if a password is specified in the configuration file. Following is an example of network share specifications.The user for the application installation directory has only read permissions. For both the input and output network shares, a prompt will display, requiring a user to enter a password. InputUncPath=\\AppInstallerServer\AppInstallers\ThinAppMigration InputMountUserName=readonlyUser OutputUncPath=\\DeploymentServer\ThinAppProj OutputMountUserName=readwriteUser OutputMountPasswordPrompt=true ThinApp Converter Logic for Detecting the Application Installation Processes For the application installer's network share, ThinApp Converter examines all subdirectories under the specified UNC path recursively, including their subdirectories. For each subdirectory, it determines which command to run for silent application installation using the following logic:
If none of the steps enable ThinApp Converter to find a correct installation command, the subdirectory is skipped. A warning is logged in the log file. You must remove all network connections to the file server referenced in the INI file from the host on which you run ThinApp Converter, to prevent conflict between user credentials. Specify the file path to the global Package.ini override file. This optional parameter enables you to specify a global override file for Package.ini that is generated for each ThinApp project. The values in the override file are merged into Package.ini in the ThinApp project that is generated for each application. Global overrides are useful when you have a global policy setting, for example, PermittedGroup in Package.ini. A Package.ini override file is formatted like a standard Windows INI file. You can add INI parameters and values that are relevant to the Package.ini file. The path is relative to the application installer's network share. Using the example for specifying the network shares for the application installers and ThinApp projects, if you specify PackageIniOverrideFile=override.ini, ThinApp Converter will try to find the file under \\AppInstallerServer\AppInstaller. You can provide a more explicit value by using predefined variables. For more information, see Predefined Environment Variables. You can specify a Package.ini file for each application. This process is described as part of the [AppSettings:AppName] section. Specify a comma- or semicolon-separated list of application directories that ThinApp will skip when searching for application installers. You can specify wildcards for DOS-style file names. For example, Microsoft*. ? and * are supported. Following is an example of an exclusion specification using a wildcard. ExclusionList=App?.old;FireFox1.0 Specify the file path to the project post processing command. The file path is relative to the application installer's network share. Using the example for specifying the network shares for the application installers and ThinApp projects, if you specify ProjectPostProcessingCommand=addscript.bat, ThinApp Converter will try to find the file under \\AppInstallerServer\AppInstaller. You can provide a more explicit value by using predefined variables. For more information, see Predefined Environment Variables. Specify whether ThinApp Converter should stop converting an application if it encounters an error, or continue with the other applications. The default value is false. Specify whether the ThinApp Converter should build the ThinApp Projects into packages following capture. Specify whether ThinApp Converter should try to detect if an application installer is stalled, for example when the application is waiting for user input on the guest virtual machine because incorrect silent installation switches were specified. The default value is true. ThinApp Converter might not be able to detect all situations in which the installer is idle. Specify how long ThinApp Converter should wait for an application installer to finish before it quits. By default, the value is 7200 seconds. This optional section provides parameters that you can use to add settings that are specific to an application. AppName is the actual name of the subdirectory that contains the application installer. These parameters can be added to each AppSettings section. In most circumstances, you will not need to configure this section. Specify how ThinApp Converter should start the application installer. If there is no value, ThinApp Converter attempts to select one installation command using the logic described in ThinApp Converter Logic for Detecting the Application Installation Processes. The Package.ini override file that is applied to a single application installer. When this parameter has a value, the global override file is processed first, followed by this application-specific override file. The file path is relative to the application installer subdirectory. Using the example at the bottom of this section, if you specify PackageIniOverrideFile=override.ini, ThinApp Converter will try to find the file under \\AppInstallerServer\AppInstaller\Adobe. You can provide a more explicit value by using predefined variables. For more information, see Predefined Environment Variables. Specify the project post processing command for the specific application. When this parameter has a value, the global override file is processed first, followed by this application-specific post processing command. Following is an example of how to apply an application-specific override during post processing. InstallationCommand=AdbeRdr920_en_US.exe /sAll PackageIniOverrideFile=override.ini InstallationCommand=silent_install.bat ProjectPostProcessingCommand=%AppInstallerDir%\addscript.bat |
Customizing the snapshot.ini File The snapshot.ini configuration file specifies what registry keys to exclude from a ThinApp project when you capture an application. For example, if you use Internet Explorer 7, you might need ThinApp to capture the following registry keys:
If the snapshot.ini file excludes the HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Connections key by default, you can remove this key from the snapshot.ini file to ensure that ThinApp captures the key in the capture process. If you do not customize the snapshot.ini file, the snapshot process loads the file from one of these locations:
This location is the AppData directory of the user.
This is the location from which ThinApp runs the snapshot.exe utility. |
Implement Scripts in a ThinApp Environment Related topics Add a Value to the System Registry You might implement a script in the following circumstances:
You can use any filename. ThinApp adds all .vbs files to the package at build time. |
Add a Value to the System Registry This script procedure adds a value to the physical system registry. Add a value to the system registry
Function OnFirstParentStart
RegFileName = ExpandPath("%Personal%\thin.reg") Set fso = CreateObject("Scripting.filesystemObject") Set RegFile = fso.CreateTextFile(RegFileName, true) The %Personal% directory is a directory that has Merged isolation mode by default.
RegFile.WriteLine("Windows Registry Editor Version 5.00") RegFile.WriteBlankLines(1) RegFile.WriteLine("[HKEY_CURRENT_USER\Software\Thinapp\demo]") RegFile.WriteLine(chr(34) & "InventoryName" & chr(34) & "=" & chr(34) & GetBuildOption("InventoryName") & chr(34)) RegFile.Close
RegEditPid = ExecuteExternalProcess("regedit /s " & chr(34) & RegFileName & chr(34)) WaitForProcess RegEditPid, 0 Wait until the process is complete.
fso.DeleteFile(RegFileName) End Function |
Cadence 15.2運行錯誤,提示缺乏dll,但環境變量(HKEY_LOCAL_MACHINE.txt文件)裏是有路徑配置的:
1、@ 2、%、%% 3、:、:: 4、~ 5、>、>> 6、| 7、^ 8、& 9、&&、|| 10、() 11、+、-、*、/ 12、equ、neq、lss、leq、gtr、geq |