Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cscript.exe cannot be found when using with electron-forge #123

Open
GrosuCristi opened this issue Jun 23, 2024 · 0 comments
Open

cscript.exe cannot be found when using with electron-forge #123

GrosuCristi opened this issue Jun 23, 2024 · 0 comments

Comments

@GrosuCristi
Copy link

There is an internal bug that happens inside regedit when using it together with electron forge. I posted a question on stackoverflow about this problem here.

Recreating the issue

To recreate this issue you will have to make an electron-forge project first. In my case I used electron-forge with the webpack plugin.
Use the command below to create the project:
npm init electron-app@latest my-new-app -- --template=webpack
of course install regedit too:
npm i regedit
Then you will have to add some code to the main process file to use any method from regedit that will access the registry. Also make sure to have all .vbs files in your project somewhere. In this example i put them inside "/PROJECT_DIR/resources/vbs/"

// other imports...
const regedit = require('regedit')
regedit.setExternalVBSLocation(path.join(process.cwd(), "resources/vbs");
regedit.list(['HKCU\\SOFTWARE', 'HKLM\\SOFTWARE', 'HKCU\\IM_FAKE_THEREFOR_I_DONT_EXIST'], function(err, result) {
    if (err) console.log(err)
    else console.log(result)
})

// the rest of the main process code remains below...

now start the app:
npm start

You should now get an error that csript.exe cannot be found.

Some useful information that I found

So I digged inside the code of the regedit package and found that a weird thing happens inside the baseCommand method.
This is how it is defined:

function baseCommand(cmd, arch) {
	let scriptPath

	// test undefined, null and empty string
	if (externalVBSFolderLocation && typeof(externalVBSFolderLocation) === 'string') {
		scriptPath = externalVBSFolderLocation
	} else {
		scriptPath = path.join(__dirname, 'vbs')
	}

	return ['//Nologo', path.join(scriptPath, cmd), arch]
}

As we set the external vbs location the if condition should be truthy. In addition, scriptPath should take the value of externalVBSFolderLocation. But in the end, it doesn't even though the code inside the if block executes because the condition is true.
Here is how to prove it by adding some console logs:

function baseCommand(cmd, arch) {
    let scriptPath

    // test undefined, null and empty string
    if (externalVBSFolderLocation && typeof(externalVBSFolderLocation) === 'string') {
        scriptPath = externalVBSFolderLocation
        console.log(scriptPath) // Logs: "C:\Users\alex\Desktop\projectdir\resources\vbs\"
    } else {
        console.log("I got executed") //  This will not log
        scriptPath = path.join(__dirname, 'vbs')
    }
    console.log(scriptPath) // Logs "undefinedvbs" which is very strange
    return ['//Nologo', path.join(scriptPath, cmd), arch]
}

Now by restarting the project you should see some logs to the console that match those from baseCommand.

A quick fix

Here is a workaround that i used:

function baseCommand(cmd, arch) {
    return ['//Nologo', path.join(externalVBSFolderLocation, cmd), arch]
}

But i think this problem should be fixed in a more proffessional manner.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant