2009年3月20日星期五

Code snippets of Htm2Pic Command Line Tool

VB

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


Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long

Private Declare Function GetExitCodeProcess Lib "kernel32" (ByVal hProcess As Long, lpExitCode As Long) As Long

Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long


Const PROCESS_QUERY_INFORMATION = &H400
Const STILL_ALIVE = &H103

Private Sub Command1_Click()

Dim pid As Long
'change to vbHide to disable prompt window
pid = Shell("c:\Htm2PicCmdLine.exe /url http://www.google.com", vbNormalFocus)
hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, 0, pid)

Do
Call GetExitCodeProcess(hProcess, ExitCode)
DoEvents
Loop While ExitCode = STILL_ALIVE
Call CloseHandle(hProcess)

MsgBox ("done")
End Sub

VC

1
2
3
4
5
6
7
8
9
10
11
12
SHELLEXECUTEINFO ShExecInfo = {0};
ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
ShExecInfo.hwnd = NULL;
ShExecInfo.lpVerb = NULL;
ShExecInfo.lpFile = "c:\\Htm2PicCmdLine.exe";
ShExecInfo.lpParameters = "/url http://www.google.com";
ShExecInfo.lpDirectory = NULL;
ShExecInfo.nShow = SW_SHOW;
ShExecInfo.hInstApp = NULL;
ShellExecuteEx(&ShExecInfo);
WaitForSingleObject(ShExecInfo.hProcess,INFINITE);

Delphi

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

var
SEI: SHELLEXECUTEINFO;
begin
with SEI do

begin
cbSize := SizeOf(SEI);
fMask := SEE_MASK_NOCLOSEPROCESS;

Wnd := Application.Handle;
lpVerb := nil;

lpFile := 'C:\Htm2PicCmdLine.exe';
lpParameters := '/url http://www.google.com';
lpDirectory := nil;

nShow := SW_SHOW;
hInstApp := 0;
lpIDList := nil;

end;
ShellExecuteEx(@SEI);
WaitForSingleObject(SEI.hProcess, INFINITE);

end;

C#

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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61

using System.Runtime.InteropServices;

public struct ShellExecuteInfo

{
public int cbSize;
public uint fMask;

public IntPtr hwnd;
public string lpVerb;
public string lpFile;

public string lpParameters;
public string lpDirectory;
public int nShow;

public IntPtr hInstApp;
public int lpIDList;
public string lpClass;

public IntPtr hkeyClass;
public uint dwHotKey;
public IntPtr hIcon;

public IntPtr hProcess;
}

public const int SW_SHOW = 5;

public const uint SEE_MASK_NOCLOSEPROCESS = 64;

[DllImport("shell32.dll")]

public static extern bool ShellExecuteEx(ref ShellExecuteInfo lpExecInfo);


[DllImport("Kernel32.dll")]
public static extern uint WaitForSingleObject(System.IntPtr hHandle, uint dwMilliseconds);


[DllImport("Kernel32.dll")]
public static extern bool GetExitCodeProcess(System.IntPtr hProcess, ref uint lpExitCode);


private void button1_Click(object sender, EventArgs e) it55.com
{

ShellExecuteInfo vShellExecuteInfo = new ShellExecuteInfo();
vShellExecuteInfo.cbSize = Marshal.SizeOf(vShellExecuteInfo);

vShellExecuteInfo.lpFile = @"C:\Htm2PicCmdLine.exe";
vShellExecuteInfo.lpParameters = @"/url http://www.google.com";

vShellExecuteInfo.nShow = SW_SHOW;
vShellExecuteInfo.fMask = SEE_MASK_NOCLOSEPROCESS;

ShellExecuteEx(ref vShellExecuteInfo);
WaitForSingleObject(vShellExecuteInfo.hProcess, int.MaxValue);

GetExitCodeProcess(vShellExecuteInfo.hProcess, ref i);
}

Java

1
2
3
4
5
6
7
8
9
10
11

try {
Runtime rt = Runtime.getRuntime();

Process proc = rt
.exec("C:\\Htm2PicCmdLine.exe /url http://www.google.com");
int exitVal = proc.waitFor();

} catch (Throwable t) {
t.printStackTrace();

}

use the system’s built-in “wscript.shell” activex component to run any program.



VB Script

1
2
3
4
set ws=wscript.createobject("wscript.shell")

ws.run "c:\htm2piccmdline.exe /url http://www.google.com", 0, true
ws.popup "done"
set ws=nothing

Java Script

1
2
3
var ws = new ActiveXObject("wscript.shell");

ws.run("c:\\htm2piccmdline.exe /url http://www.google.com", 0, true);
document.write("done!");

PHP

1
2
3
4
5

$ws = new COM("wscript.shell") or die("Can't start wscript.shell!");

$ws->run("c:\htm2piccmdline.exe /url http://www.google.com", 0, true);

echo "done!";
?>

没有评论:

发表评论