I used the child-process module of node.js. And i registered node binary exe file with windows service. Powershell and folderbrowserdialog are used as child-process. However, it seems to end at the same time as the child-process starts.
Below is my code
const spawn = require('cross-spawn')
const child = spawn("cmd.exe",["/c","powershell.exe","ps\\ps.ps1"])
console.log('path')
child.stdout.on("data",function(data){
path = data.toString()
});
child.on("exit",function(){
res.send(path)
});
child.stdin.end();
This code does not work only when running as a window service. res.send(path) is alwayse empty("")
my ps code is.
Function Get-Folder($initialDirectory="")
{
[System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms")|Out-Null
$foldername = New-Object System.Windows.Forms.FolderBrowserDialog
$foldername.rootfolder = "MyComputer"
$foldername.Description = "slect folder"
$foldername.SelectedPath = $initialDirectory
$caller = [System.Windows.Forms.NativeWindow]::new()
$caller.AssignHandle([System.Diagnostics.Process]::GetCurrentProcess().MainWindowHandle)
if($foldername.ShowDialog($caller) -eq [Windows.Forms.DialogResult]::"OK")
{
$folder += $foldername.SelectedPath
}else{
$folder = "D:\\"
}
return $folder
}
Get-Folder