I have a bit of a (at least for me) odd problem. I have created a (Java) Application which (when some conditions are meet) runs a PowerShell script that uses MS-Word to print some document. I run this application through a simple batch file (java call).
It works like a charm when I run the application through my batch, BUT when I (using NSSM or AlwaysUp) turn it into a windows service the and trigger the printing process it fails. I see in the task manager that a MS-Word process is started, and it take away lots of CPU, but it does nothing (no matter how long I wait).
Simplified code:
$objOffice = New-Object -comobject Excel.Application
$objDoc = $objOffice.Workbooks.Open("C:\printTest\printFile.xlsx")
$objDoc.printout()
$objDoc.Close($false)
$objOffice.quit()
I have tested this on other computers as well... Same result.
Also interesting:
EDIT: This part written where was my fault, and fixed it.
At this point I am not even sure that it has something to do with the powershell command, but I am getting out of ideas.
Start-Process -FilePath 'C:\printTest\printFile.xlsx' -Verb print
Also, take a look at this page, which says
You might notice the option for “Allow service to interact with desktop”, which we mentioned earlier – by default, services are not
allowed to access your desktop unless this box is checked, and this
checkbox is really only there for legacy support.
But just checking
that box doesn’t immediately give them access – you would also need to
make sure that the NoInteractiveServices value in the registry is set
to 0, because when it is set to 1, that checkbox is ignored and
services can’t interact with the desktop at all. Note: in Windows 8,
the value is set to 1, and interactive services are prohibited.
Related
I can't execute VBScript using WIX installer. Currently I have this part of WiX config:
<Binary Id='KillThatProcessBinary' SourceFile='KillThatProcess.vbs' />
<CustomAction Id="KillThatProcessAction"
Execute="immediate"
BinaryKey='KillThatProcessBinary'
VBScriptCall='KillThatProcessFunction'
Return="check"/>
<InstallExecuteSequence>
<Custom Action='KillThatProcessAction' Before='InstallValidate'/>
<ScheduleReboot After="InstallFinalize"/>
</InstallExecuteSequence>
And this VBS script (KillThatProcess.vbs):
Public Function KillThatProcessFunction()
Set oShell = WScript.CreateObject("WSCript.shell")
oShell.run "cmd /C wmic process where ""name like '%java%'"" delete"
Return 0
End Function
I already try to insert this script into CustomAction (as innerText), and add attribute: Script="vbscript". But nothing works, every time I got the error message - "There is a problem with this Windows Installer package. A script reqired for this install to complete could not be run. Contact your support personnel or package vendor."
And errors in log file:
Error 0x80070643: Failed to install MSI package.
[1A88:2FA4][2018-08-21T14:11:17]e000: Error 0x80070643: Failed to configure per-user MSI package.
[1A88:2FA4][2018-08-21T14:11:17]i319: Applied execute package: LPGateway, result: 0x80070643, restart: None
[1A88:2FA4][2018-08-21T14:11:17]e000: Error 0x80070643: Failed to execute MSI package.
I already execute this vbs script (not from installer) and it works. Anybody know what I do wrong?
There are a few issues I want to summarize:
VBA & VBScript Functions: That VBScript looks like it is actually VBA and calling VBScript in an MSI requires a bit of tweaking
to call VBScript functions properly.
Reboot: The reboot you schedule must get a better condition to avoid unexpected reboots.
Process Kill: What process are you trying to kill?
Elevation: If it is elevated you need to run the kill elevated for it to succeed. Your per-user setup is likely not set to
elevate at all (so you can generally only end processes running as yourself).
Restart Manager: Very often you do not need to kill processes, due to the Restart Manager feature of Windows that Windows
Installer tries to use. Attempt to explain this feature (look for
yellow sections).
Issue 1: That must be a VBA script and not a VBScript? For the record: I haven't seen return in VBScript? In VBScript you return from a function by setting the function name equal to whatever you want to return, quick sample:
result = IsEmptyString("")
MsgBox CStr(result)
Function IsEmptyString(str)
If str = "" Then
IsEmptyString = True
Else
IsEmptyString = False
End If
End Function
Note: The above is just a silly, rather meaningless example. For more elaborate checking try
IsBlank from ss64.com. VBScript comes with the functions IsEmpty and IsNull and IsObject.
When used in MSI files, I normally don't add a function in the VBScript, but just run the script directly, so running this VBScript should work:
MsgBox(Session.Property("ProductName"))
Inserting it into the WiX source (notice no function call specified):
<Binary Id='Sample.vbs' SourceFile='Sample.vbs' />
<CustomAction Id='Sample.vbs' VBScriptCall='' BinaryKey='Sample.vbs' Execute='immediate' Return='ignore'/>
Crucially your VBScript can still call other functions available in the same VBScript file. So in the above sample "IsEmptyString" can be called from the main "nameless" function at the top of the file.
Check Exit Code: And finally, any custom action set to check exit code can throw your setup into abort (immediate mode) or rollback (deferred mode). I would only check the exit code if you have to end the setup if the custom action can not run.
Issue 2: Reboots. This is a very serious issue in my opinion. I have seen people sent out the door for causing unexpected reboots during large scale deployments. Rebooting a knowledge worker's PC (and their managers) with a dozen Visual Studio windows open, dozens of browser windows and Word and Excel and you name it. It can cause a great deal of problems. And they may know where you live! :-)
Please read the following answer (at least its 3 bullet points at the beginning): Reboot on install, Don't reboot on uninstall
Issue 3: Process Kill. As indicated above the killing of processes is related to the reboot issues. It is not always necessary to kill processes if they are compliant with Windows Restart Manager as explained in the link above. Let me repeat it here (yellow sections should give you the gist of it - especially the second one I think).
There are a few different ways to kill processes. Note that the most common problem might be that you don't have the access rights and / or privileges to kill the process - no matter what tool or approach you use to do so.
Perhaps you can try the CloseApplication feature from the Util schema: http://wixtoolset.org/documentation/manual/v3/xsd/util/closeapplication.html
In Wix MSI: Killing a process upon uninstallation
Kill windows service forcefully in WIX (towards bottom)
Kill process using WMI / VBScript
Some people combine taskill.exe and WiX by means of the Quiet Execution Custom Action (CAQuietExec: hide command line windows). FireGiant documentation.
I am not sure which of these options to recommend. I don't like the concept of killing processes altogether, but sometimes there is no other option I guess.
I've inherited and am maintaining a scala/play app that was built several years ago (2014). Every night there's a cron job executing a shell script to restart the app. Running this script from the command line at any time works just fine as well. The app stops, cleans up, rebuilds then restarts.
I've been asked to build a php page which will allow this same shell script to be run via php. I thought it would be very straightforward, but when I exec() the same shell script, I get the output message, ""No java installations was detected."
But of course it is there, where the variables say it should be.
I've tried cd'ing into the directory first before executing the script, and I've tried executing the script as the owner/user of the cpanel account (which is generally how the script is run from the command line). Always the same message. I temporarily tried adding the user to the wheel group (terrible idea long-term I know), but even that didn't work.
I thought it must be some sort of cpanel or server issue, and reached out to the host of the VPS but they didn't think so. The developer of the app is no longer reachable. My guess is it's something he could fix in 5 minutes, I just have no familiarity with this framework.
I've reviewed everything I can online several times and just don't see anything relevant...
Any leads would be greatly appreciated!
I'm designing a console application for a server running RedHat. The end users should be able to run this app with any terminal of their choosing. (For example; Gnome Terminal, Putty SSH/ Telnet, MS Telnet Client and others).
In most terminal applications there's nothing wrong, however when I launch my program from a MS telnet session I notice my special inputs for System.in and System.console() get totally messed up. A backspace will write ^H to the screen and other keys write gibberish as well.
I've hacked at it enough that I can get it to consistently work, but I'm sure what I'm doing is gross:
if (!System.getenv("TERM").equals("xterm"))
{
System.out.println("\nWARNING: The TERM type is now set to xterm\n");
final String[] cmd = { "/bin/sh", "-c", "export TERM=xterm" };
Runtime.getRuntime().exec(cmd);
}
Would there be an issue here for terminals that don't support xterm? I notice that the Microsoft Telnet client doesn't allow you to set the TERM type to xterm before you begin a session. Once the session is started, however, setting TERM=xterm seems to solve the problem.
How do most console applications go about this issue?
With character terminal applications, there are always two ends in the communication, which must agree on how to interpret the control characters. Usually both sides are capable of using a variety of codings described in termcap/terminfo database.
On the Unix server-side you can define the coding by setting the TERM environmental variable, or by using stty (a default is used otherwise, often a dumb terminal emulation).
On the client side you also have to set the same terminal emulation as on the server side. Windows native telnet has the capability to define the emulation (see e.g. Configure the Telnet Terminal Type), as have other terminal emulators (e.g. Putty), too.
Regarding your design decisions: The above terminal setting are usually only described in user documentation, and not hardcoded in application, to leave more flexibility. After all, you do not know in advance which terminal (only a simple hardware terminal, supporting a single termcap coding, perhaps?) your users are going to use.
(As your question has little to do with Java or system.in, so you could re-consider the tags you use.)
You should look into these two posts, as they are related to what you are doing.
check env variable
set environment variable
As you are running the console on top of the Unix server, redhat in your case, I would also recommend that you look into the Unix command expect, that allows you to read the input in the console application, and performs the action according to the input of the user.
Here are some examples of the command usage.
sample Expect usages
Due to a suite of antivirus and security policies, a java applet I developed for my organization loads very slowly. The problem is not the cache or the applet, but rather it's JVM. When Windows first loads, if I go to command window and enter "java", it will take nearly a minute for the response (the command usage text) to come up. Subsequent commands are responded immediately.
So, one mitigation I can think of is to set all users to run java once as they login. I can either put a shortcut to Start Up folder in the start menu, or create a registry key. If I want this to be as least intrusive as possible (load it in background and in low priority), what's the best way to do this?
Did you consider Windows Task Scheduler and task that starts on windows start-up?
You can add the call to java to the registry, under
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run
http://msdn.microsoft.com/en-us/library/aa376977(v=vs.85).aspx
But what about not using java?
I am unable to run more than one instance of java webstart at any given time.
For example, I am unable to run both the production & QA instance of an application at once, both of which are launched via java webstart. Additionally, I am unable to run the java webstart cache viewer at the same time as either the production or QA instance of my application.
I am however able to run any of the above three webstart launches when they are run in isolation of each other. When I try to bring up a second option, I see the 'Java Loading...' screen which then disappears and nothing happens.
Additionally, I have tried to delete the webstart cache (via the java webstart cache viewer) and I receive the following error regardless of which JRE I point to:
"Bad installation. Error invoking Java VM (execv)
'path to my javaw.exe'"
I expect both the problems I mention above are interlinked. I do not believe I have changed any configuration recently and I have been happily running java webstart for years.
Has anyone seen such a problem before?
Thanks,
Jack
EDIT: When the second instance of webstart attempts to run, during the display of the 'Java Loading...' screen I can see in the task manager that a new javaw.exe process is spawned. This process almost immediately dies though. I'm not sure how to inspect the failure in that process, but I expect it is similar to the failure when trying to clear my cache through the webstart cache viewer.
You may be able to use javaws from the command line to run a second instance in -offline mode. The verbose option is handy, too.
javaws -offline -verbose MyApplication.jnlp
I think it is because both instances of the application use the same folder as current working directory. I do not remember exactly but it is somewhere under user home and the folder contains the application name or something...
So, if this is correct the solution is to change the application name like "My Application - QA" vs. "My Application" used on production.
The name is somewhere in jnlp.xml.
The reason may be the startup parameters for client java/javaw, which do not allow to run more than one instance of Java. For example because of set debug port. These parameters can be set in the command line or in the Java Control Panel -> Java -> button View.