private void SetStaticIpv4Setting() { string macaddr = mac.value; resetError(); if (address.Exists() || gateway.Exists()) { foreach (ManagementObject nic in WmiBase.Singleton.Win32_NetworkAdapterConfiguration) { if (!(bool)nic["ipEnabled"]) { continue; } if (nic["macAddress"].ToString().ToUpper() != macaddr.ToUpper()) { continue; } try{ if (address.Exists()) { string ipv4, netmask; convertIpv4Mask(address.value, out ipv4, out netmask); ManagementBaseObject objNewIP = nic.GetMethodParameters("EnableStatic"); objNewIP["IPAddress"] = new string[] { ipv4 }; objNewIP["SubnetMask"] = new string[] { netmask }; if (setIpv4Network(nic, "EnableStatic", objNewIP, "ipv4 address setting") != 0) { return; } } if (gateway.Exists()) { ManagementBaseObject objNewGate = nic.GetMethodParameters("SetGateways"); objNewGate["DefaultIPGateway"] = new string[] { gateway.value }; if (setIpv4Network(nic, "SetGateways", objNewGate, "ipv4 gateway setting") != 0) { return; } } } catch (Exception e) { errorCode.value = "1"; errorMsg.value = e.ToString(); wmisession.Log("Exception " + e.ToString()); return; } } } }
override protected void onFeature() { if (controlKey.Exists() && !state.Exists()) { try { if (error.Exists()) { error.Remove(); } if (!domainName.Exists()) { error.value = "domainname must be specified"; throw new Exception("domainname must be specified"); } if (!userName.Exists()) { error.value = "username must be specified"; throw new Exception("username must be specified"); } if (!password.Exists()) { error.value = "password must be specified"; throw new Exception("password must be specified"); } if (controlKey.value.Equals("joindomain")) { JoinDomain(); } else if (controlKey.value.Equals("unjoindomain")) { UnjoinDomain(); } // If completed, remove the arguments, to avoid // them hanging around in xenstore. domainName.Remove(); userName.Remove(); password.Remove(); } catch (Exception e) { if (!error.Exists()) { error.value = e.ToString(); } state.value = "Failed"; } finally { // We always want to remove the controlKey, so that // it can be set again controlKey.Remove(); } } }
private void SetStaticIpv6Setting() { string macaddr = mac.value; resetError(); if (address6.Exists() || gateway6.Exists()) { foreach (ManagementObject nic in WmiBase.Singleton.Win32_NetworkAdapterConfiguration) { if (!(bool)nic["ipEnabled"]) { continue; } if (nic["macAddress"].ToString().ToUpper() != macaddr.ToUpper()) { continue; } try{ if (address6.Exists()) { string argument = "interface ipv6 set address {0} {1}"; argument = string.Format(argument, nic["interfaceIndex"], address6.value); if (netshInvoke(argument) != 0) { return; } } if (gateway6.Exists()) { string argument = "interface ipv6 add route ::/0 {0} {1}"; argument = string.Format(argument, nic["interfaceIndex"], gateway6.value); if (netshInvoke(argument) != 0) { return; } } } catch (Exception e) { errorCode.value = "1"; errorMsg.value = e.ToString(); wmisession.Log("Exception " + e.ToString()); return; } } } }
void onFeatureWrapper(object nothing, EventArrivedEventArgs args) { try { if (enabled && ((!controlmustexist) || controlKey.Exists())) { onFeature(); } } catch (System.Management.ManagementException e) { enabled = false; if (e.ErrorCode == ManagementStatus.AccessDenied) { wmisession.Log("Feature " + name + " disabled"); } else { throw e; } } catch (Exception e) { enabled = false; //Don't want to call the feature if it causes an exception exceptionhandler.HandleException("Feature " + name, e); } }
void onServerClipboard() { string newclipboard = null; try { if (xsSetClipboard.Exists()) { newclipboard = xsSetClipboard.value; Debug.Print("get new clipboard " + newclipboard); xsSetClipboard.Remove(); } else { return; } } catch { return; } if (newclipboard == null) { currentclipboard = totalclipboard; setClientClipboard(totalclipboard); totalclipboard = ""; } else { totalclipboard += newclipboard; } }
override protected void onFeature() { if (controlKey.Exists() && !state.Exists()) { try { if (error.Exists()) { error.Remove(); } if (warn.Exists()) { warn.Remove(); } if (state.Exists()) { error.value = "Setting name already in progress"; state.value = "Failed"; return; } if (controlKey.value.Equals("set")) { SetComputerName(); } else { error.value = "Unknown action : " + controlKey.value; state.value = "Failed"; } } catch (Exception e) { if (!error.Exists()) { error.value = e.ToString(); } state.value = "Failed"; } finally { // We always want to remove the controlKey, so that // it can be set again controlKey.Remove(); } } }
protected override void onFeature() { if (!datats.Exists()) { bool enabled = query(); string newtsvalue = (enabled ? "1" : "0"); wmisession.Log("Setting data/ts to " + newtsvalue); datats.value = newtsvalue; } }
void addLicenseInfoToStore() { try { if (oslicense.Exists()) { oslicense.Remove(); } switch (Win32Impl.IsGenuineWindows()) { case Win32Impl.SL_GENUINE_STATE.SL_GEN_STATE_INVALID_LICENSE: oslicense.value = licenseinvalid; break; case Win32Impl.SL_GENUINE_STATE.SL_GEN_STATE_IS_GENUINE: oslicense.value = licensegenuine; break; case Win32Impl.SL_GENUINE_STATE.SL_GEN_STATE_TAMPERED: oslicense.value = licensetampered; break; default: break; } } catch { //Do nothing if IsGenuineWindows doesn't exist }; try { if (osvirtualxp.Exists()) { osvirtualxp.Remove(); } if (Win32Impl.GetWindowsInformation("VirtualXP-licensing-Enabled") != 0) { osvirtualxp.value = "1"; } else { osvirtualxp.value = "0"; } } catch (Exception e) { WmiBase.Singleton.DebugMsg("GetWindowsInformation failed: \n" + e.ToString()); } }
void onClientClipboard() { if (xsReportClipboard.Exists()) { string newclipboard = xsReportClipboard.value; } else { // There is nothing set if (totalclientclipboard != null) { string tempclip; if (totalclientclipboard.Length > 1024) { tempclip = totalclientclipboard.Substring(0, 1024); totalclientclipboard = totalclientclipboard.Substring(1024, totalclientclipboard.Length - 1024); } else { tempclip = totalclientclipboard; totalclientclipboard = ""; } xsReportClipboard.value = tempclip; if (tempclip.Equals("")) { if (currentclipboardchanged) { currentclipboardchanged = false; totalclientclipboard = currentclipboard; } else { totalclientclipboard = null; } } } } }
void snapshotThreadHandler() { try { WmiBase.Singleton.DebugMsg("SnapshotThread"); if (!typeKey.Exists()) { type = VssSnapshot.Type.VM; } else { switch (typeKey.value) { case "volume": type = VssSnapshot.Type.VOLUME; break; case "vm": default: type = VssSnapshot.Type.VM; break; } } List <String> volumeNames; if (type == VssSnapshot.Type.VM) { volumeNames = ListXenVolumes(); } else { volumeNames = ListXenStoreVolumes(); } using (VssSnapshot vss = new VssSnapshot(type, volumeNames)) { Debug.Print("Create snapshot"); vss.CreateSnapshotSet(); Debug.Print("Created snapshot"); statusKey.value = "snapshot-created"; } } catch (VssSnapshotException vsse) { Debug.Print(vsse.ToString()); try { wmisession.GetXenStoreItem("control/snapshot/error/message").value = GetHresult(vsse.code); wmisession.GetXenStoreItem("control/snapshot/error/code").value = vsse.code.ToString(); wmisession.GetXenStoreItem("control/snapshot/error").value = vsse.state; statusKey.value = "snapshot-error"; } catch {} } catch (Exception e) { Debug.Print(e.ToString()); try { wmisession.GetXenStoreItem("control/snapshot/error").value = "Unknown Error"; statusKey.value = "snapshot-error"; } catch {} } Debug.Print("Snapshot done"); }
protected override void onFeature() { if (controlKey.Exists()) { try { foreach (string vif in staticIpSetting.children) { mac = wmisession.GetXenStoreItem(vif + "/static-ip-setting/mac"); ipenabled = wmisession.GetXenStoreItem(vif + "/static-ip-setting/enabled"); ipv6enabled = wmisession.GetXenStoreItem(vif + "/static-ip-setting/enabled6"); errorCode = wmisession.GetXenStoreItem(vif + "/static-ip-setting/error-code"); errorMsg = wmisession.GetXenStoreItem(vif + "/static-ip-setting/error-msg"); if (ipenabled.Exists() && ipenabled.value.Length != 0) { if (int.Parse(ipenabled.value) == 1) // assign static ip setting { address = wmisession.GetXenStoreItem(vif + "/static-ip-setting/address"); gateway = wmisession.GetXenStoreItem(vif + "/static-ip-setting/gateway"); SetStaticIpv4Setting(); wmisession.Log("Static ip setting is assigned."); } else // remove static ip setting { UnsetStaticIpv4Setting(); wmisession.Log("Static ip setting is unassigned."); } } if (ipenabled.Exists()) ipenabled.Remove(); if (ipv6enabled.Exists() && ipv6enabled.value.Length != 0) { if (int.Parse(ipv6enabled.value) == 1) // assign static ipv6 setting { address6 = wmisession.GetXenStoreItem(vif + "/static-ip-setting/address6"); gateway6 = wmisession.GetXenStoreItem(vif + "/static-ip-setting/gateway6"); SetStaticIpv6Setting(); wmisession.Log("Static ipv6 setting is assigned."); } else // remove static ipv6 setting { UnsetStaticIpv6Setting(); wmisession.Log("Static ipv6 setting is unassigned."); } } if (ipv6enabled.Exists()) ipv6enabled.Remove(); } } catch { }; // Ignore failure, if node does not exist } }
protected override void onFeature() { if (controlKey.Exists()) { try { foreach (string vif in staticIpSetting.children) { mac = wmisession.GetXenStoreItem(vif + "/static-ip-setting/mac"); ipenabled = wmisession.GetXenStoreItem(vif + "/static-ip-setting/enabled"); ipv6enabled = wmisession.GetXenStoreItem(vif + "/static-ip-setting/enabled6"); errorCode = wmisession.GetXenStoreItem(vif + "/static-ip-setting/error-code"); errorMsg = wmisession.GetXenStoreItem(vif + "/static-ip-setting/error-msg"); if (ipenabled.Exists() && ipenabled.value.Length != 0) { if (int.Parse(ipenabled.value) == 1) // assign static ip setting { address = wmisession.GetXenStoreItem(vif + "/static-ip-setting/address"); gateway = wmisession.GetXenStoreItem(vif + "/static-ip-setting/gateway"); SetStaticIpv4Setting(); wmisession.Log("Static ip setting is assigned."); } else // remove static ip setting { UnsetStaticIpv4Setting(); wmisession.Log("Static ip setting is unassigned."); } } if (ipenabled.Exists()) { ipenabled.Remove(); } if (ipv6enabled.Exists() && ipv6enabled.value.Length != 0) { if (int.Parse(ipv6enabled.value) == 1) // assign static ipv6 setting { address6 = wmisession.GetXenStoreItem(vif + "/static-ip-setting/address6"); gateway6 = wmisession.GetXenStoreItem(vif + "/static-ip-setting/gateway6"); SetStaticIpv6Setting(); wmisession.Log("Static ipv6 setting is assigned."); } else // remove static ipv6 setting { UnsetStaticIpv6Setting(); wmisession.Log("Static ipv6 setting is unassigned."); } } if (ipv6enabled.Exists()) { ipv6enabled.Remove(); } } } catch { }; // Ignore failure, if node does not exist } }
private void SetStaticIpv6Setting() { string macaddr = mac.value; resetError(); if ((address6.Exists() && address6.value.Length != 0) || (gateway6.Exists() && gateway6.value.Length != 0)) { bool FoundDevice = false; foreach (ManagementObject nic in WmiBase.Singleton.Win32_NetworkAdapterConfiguration) { if (!(bool)nic["ipEnabled"]) { continue; } if (nic["macAddress"].ToString().ToUpper() != macaddr.ToUpper()) { continue; } FoundDevice = true; IpSettings.addIpSeting(nic["macAddress"].ToString(), nic["DHCPEnabled"].ToString(), "IPV6", "", "", ""); try{ if (address6.Exists() && address6.value.Length != 0) { string argument = "interface ipv6 set address {0} {1}"; argument = string.Format(argument, nic["interfaceIndex"], address6.value); if (netshInvoke(argument) != 0) { return; } } if (gateway6.Exists() && gateway6.value.Length != 0) { string argument = "interface ipv6 add route ::/0 {0} {1}"; argument = string.Format(argument, nic["interfaceIndex"], gateway6.value); if (netshInvoke(argument) != 0) { resetError(); argument = "interface ipv6 set route ::/0 {0} {1}"; argument = string.Format(argument, nic["interfaceIndex"], gateway6.value); if (netshInvoke(argument) != 0) { return; } } } } catch (Exception e) { errorCode.value = "1"; errorMsg.value = e.ToString(); wmisession.Log("Exception " + e.ToString()); return; } } if (!FoundDevice) { errorCode.value = "101"; errorMsg.value = "Device not ready to use or ipEnabled not been set"; wmisession.Log("Device not ready to use or ipEnabled not been set"); return; } } }
private void SetStaticIpv4Setting() { string macaddr = mac.value; resetError(); if ((address.Exists() && address.value.Length != 0) || (gateway.Exists() && gateway.value.Length != 0)) { bool FoundDevice = false; foreach (ManagementObject nic in WmiBase.Singleton.Win32_NetworkAdapterConfiguration) { if (!(bool)nic["ipEnabled"]) { continue; } if (nic["macAddress"].ToString().ToUpper() != macaddr.ToUpper()) { continue; } FoundDevice = true; IpSettings.addIpSeting(nic["macAddress"].ToString(), nic["DHCPEnabled"].ToString(), "IPV4", "", "", ""); try{ if (address.Exists() && address.value.Length != 0) { string ipv4, netmask; convertIpv4Mask(address.value, out ipv4, out netmask); ManagementBaseObject objNewIP = nic.GetMethodParameters("EnableStatic"); objNewIP["IPAddress"] = new string[] { ipv4 }; objNewIP["SubnetMask"] = new string[] { netmask }; if (setIpv4Network(nic, "EnableStatic", objNewIP, "ipv4 address setting") != 0) { return; } } if (gateway.Exists() && gateway.value.Length != 0) { ManagementBaseObject objNewGate = nic.GetMethodParameters("SetGateways"); objNewGate["DefaultIPGateway"] = new string[] { gateway.value }; if (setIpv4Network(nic, "SetGateways", objNewGate, "ipv4 gateway setting") != 0) { return; } } } catch (Exception e) { errorCode.value = "1"; errorMsg.value = e.ToString(); wmisession.Log("Exception " + e.ToString()); return; } } if (!FoundDevice) { errorCode.value = "101"; errorMsg.value = "Device not ready to use or ipEnabled not been set"; wmisession.Log("Device not ready to use or ipEnabled not been set"); return; } } }