Line 0
Link Here
|
|
|
1 |
/** |
2 |
* In the command line: |
3 |
* cscript win32.js functionName [function arg0] [function arg1] [function arg2] |
4 |
**/ |
5 |
var exitCode = 0; |
6 |
var FileSystemObject = WScript.CreateObject("Scripting.FileSystemObject"); |
7 |
var ShellApplication = WScript.CreateObject("Shell.Application"); |
8 |
|
9 |
function Extract(zipFile, targetDir) { |
10 |
var objSource = ShellApplication.NameSpace(zipFile).Items(); |
11 |
var objTarget = ShellApplication.NameSpace(targetDir); |
12 |
//http://msdn2.microsoft.com/en-us/library/ms723207.aspx |
13 |
intOptions = 256; |
14 |
//WScript.echo("objTarobjSourceget: \"" + objSource.Count +"\"") |
15 |
objTarget.CopyHere(objSource, intOptions); |
16 |
var file = FileSystemObject.GetFile(zipFile); |
17 |
WScript.echo(FileSystemObject.GetSpecialFolder(2) + "\\*" + file.Name + "*"); |
18 |
// FileSystemObject.DeleteFolder(FileSystemObject.GetSpecialFolder(2) + "\\*" + file.Name + "*", true); |
19 |
} |
20 |
|
21 |
function FindProductCode(product) { |
22 |
var wi = WScript.CreateObject("WindowsInstaller.Installer"); |
23 |
var prods = wi.ProductsEx("", "", 7); |
24 |
for(var i = 0; i < prods.Count; i++) { |
25 |
var prod = prods.Item(i); |
26 |
var prodName =prod.InstallProperty("ProductName"); |
27 |
if (prodName.indexOf(product) != -1){ |
28 |
WScript.echo("Product: \"" + prodName +"\" is found"); |
29 |
return prod.ProductCode; |
30 |
} |
31 |
} |
32 |
} |
33 |
|
34 |
/** |
35 |
* Uninstall the product with it name |
36 |
*/ |
37 |
function Uninstall(prodName) { |
38 |
WScript.echo("Try to uninstall: \"" + prodName +"\""); |
39 |
var prodCode = FindProductCode(prodName); |
40 |
if (prodCode) { |
41 |
var shell = WScript.CreateObject("WScript.Shell"); |
42 |
//To enable Windows 7 support, change /qn to /passive |
43 |
WScript.echo("Run: msiexec /x " + prodCode + " /passive"); |
44 |
exitCode = shell.Run("msiexec /x " + prodCode + " /passive", 0, true); |
45 |
} else { |
46 |
WScript.echo("Can't find " + prodName + " to uninstall!"); |
47 |
} |
48 |
} |
49 |
|
50 |
/** |
51 |
* Clean up the product msi info with its name by using Windows Installer Clean up |
52 |
*/ |
53 |
function CleanUp(prodName) { |
54 |
WScript.echo("Try to clean: \"" + prodName +"\""); |
55 |
var prodCode = FindProductCode(prodName); |
56 |
if (prodCode) { |
57 |
var shell = WScript.CreateObject("WScript.Shell"); |
58 |
//To enable Windows 7 support, change /qn to /passive |
59 |
WScript.echo("Run: C:/Program Files/Windows Installer Clean Up/MsiZap.exe' T " + prodCode); |
60 |
exitCode = shell.Run("\"C:\\Program Files\\Windows Installer Clean Up\\MsiZap.exe\" T " + prodCode, 0, true); |
61 |
} else { |
62 |
WScript.echo("Can't find " + prodName + " to clean up!"); |
63 |
} |
64 |
} |
65 |
/** |
66 |
* Uninstall the product with it name |
67 |
*/ |
68 |
function UninstallWithGUI(prodName) { |
69 |
WScript.echo("Try to uninstall: \"" + prodName +"\""); |
70 |
var prodCode = FindProductCode(prodName); |
71 |
if (prodCode) { |
72 |
var shell = WScript.CreateObject("WScript.Shell"); |
73 |
WScript.echo("Run: msiexec /x " + prodCode); |
74 |
exitCode = shell.Run("msiexec /x " + prodCode, 1, true); |
75 |
} else { |
76 |
WScript.echo("Can't find " + prodName + " to uninstall!"); |
77 |
} |
78 |
} |
79 |
|
80 |
var args = WScript.Arguments; |
81 |
var funcName = args(0); |
82 |
var largs = []; |
83 |
for (var i = 1; i < args.Count(); i++) { |
84 |
largs.push(args(i)); |
85 |
} |
86 |
|
87 |
this[funcName].apply(this, largs); |
88 |
WScript.Quit(exitCode); |