forked from so87/CISSP-Study-Guide
-
Notifications
You must be signed in to change notification settings - Fork 0
/
printJS.bat
98 lines (81 loc) · 2.26 KB
/
printJS.bat
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
@if (@X)==(@Y) @end /* JScript comment
@echo off
cscript //E:JScript //nologo "%~f0" %*
exit /b %errorlevel%
@if (@X)==(@Y) @end JScript comment */
//gets an information that normally is acquired by right click-details
// can get image dimensions , media file play time and etc.
//////
FSOObj = new ActiveXObject("Scripting.FileSystemObject");
var ARGS = WScript.Arguments;
if (ARGS.Length < 1 ) {
WScript.Echo("No file passed");
WScript.Echo("Usage (prints with default printer a file if possible)");
WScript.Echo(WScript.ScriptName + " file");
WScript.Quit(1);
}
var filename=ARGS.Item(0);
var objShell=new ActiveXObject("Shell.Application");
/////
//fso
ExistsItem = function (path) {
return FSOObj.FolderExists(path)||FSOObj.FileExists(path);
}
getFullPath = function (path) {
return FSOObj.GetAbsolutePathName(path);
}
//
//paths
getParent = function(path){
var splitted=path.split("\\");
var result="";
for (var s=0;s<splitted.length-1;s++){
if (s==0) {
result=splitted[s];
} else {
result=result+"\\"+splitted[s];
}
}
return result;
}
getName = function(path){
var splitted=path.split("\\");
return splitted[splitted.length-1];
}
//
function main(){
if (!ExistsItem(filename)) {
WScript.Echo(filename + " does not exist");
WScript.Quit(2);
}
var fullFilename=getFullPath(filename);
var namespace=getParent(fullFilename);
var name=getName(fullFilename);
var objFolder=objShell.NameSpace(namespace);
var objItem=objFolder.ParseName(name);
//https://msdn.microsoft.com/en-us/library/windows/desktop/bb787870(v=vs.85).aspx
//https://msdn.microsoft.com/en-us/library/windows/desktop/bb774170(v=vs.85).aspx
//WScript.Echo(fullFilename + " : ");
//WScript.Echo(objFolder.GetDetailsOf(objItem,-1));
var verbs=objItem.Verbs();
objItem.InvokeVerb("Print");
/*
Language dependent version commented bellow.
InovkeVerb("Print") cannot check if the print action is supported, but works independently of language settings
*/
/*
if (verbs != null) {
//WScript.Echo(verbs.Count);
for (var i=0;i<verbs.Count;i++){
if(verbs.Item(i).Name === "&Print"){
verbs.Item(i).DoIt();
return;
}
//WScript.Echo(verbs.Item(i).Name);
}
WScript.Echo("the item " + filename + "does not support print verb");
return;
}
*/
}
main();