I'm trying to use Jacob to change the system time. I wrote the following method:
/*******************************************************************************
* Sets the system time.
*
* @param par_sSystemTime String
*******************************************************************************/
public void setSystemTime(String par_sSystemTime)
{
ActiveXComponent os =null;
ComThread.InitMTA();
try
{
InetAddress address = FoxEnvironment.getRemoteAddress(FoxEnvironment.getLocalHostName());
String connectStr = String.format("winmgmts:{impersonationLevel=impersonate, authenticationLevel=pkt}!\\\\%s\\root\\CIMV2", address.getHostName());
ActiveXComponent wmi = new ActiveXComponent(connectStr);
Variant instances = wmi.invoke("InstancesOf", "Win32_OperatingSystem");
Enumeration<Variant> en = new EnumVariant(instances.getDispatch());
os = new ActiveXComponent(en.nextElement().getDispatch());
os.invoke("SetDateTime", par_sSystemTime);
}
catch(Exception ex)
{
ex.printStackTrace();
ML.logMsg(MLCon.SERR, null, BaseMessages.GENERAL_UNEXPECTED_ERROR,"setSystemTime(): " + ex);
}
catch(NoClassDefFoundError ex)
{
ex.printStackTrace();
ML.logMsg(MLCon.SERR, null, BaseMessages.GENERAL_UNEXPECTED_ERROR,"setSystemTime(): " + ex);
}
finally
{
// Release the components
if (os != null)
{
os.safeRelease();
os = null;
}
ComThread.Release();
}
}
When executing this method, get the exception
com.jacob.com.ComFailException: Invoke of: SetDateTime Source: SWbemObjectEx Description: Access denied.
Anyone can help with this?
Thanks in advance, Valentino