Example #1
0
        public bool installing()
        {
            try
            {
                string installstate;
                if (Win32Impl.is64BitOS() && (!Win32Impl.isWOW64()))
                {
                    installstate = (string)Registry.GetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\Citrix\\XenToolsInstaller", "InstallStatus", "Installed");
                }
                else
                {
                    installstate = (string)Registry.GetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\Citrix\\XenToolsInstaller", "InstallStatus", "Installed");
                }
                if (installstate == null)
                {
                    installstate = "Installed";
                }

                if (installstate.Equals("Installed"))
                {
                    needsinstalling = false;
                    return(false);
                }
                needsinstalling = true;
                return(true);
            }
            catch
            {
                needsinstalling = true;
                return(true);
            }
        }
Example #2
0
        void addXDInfoToStore()
        {
            try
            {
                string vdapath;
                if (Win32Impl.is64BitOS() && (!Win32Impl.isWOW64()))
                {
                    vdapath = "Software\\Wow6432Node\\Citrix\\VirtualDesktopAgent";
                }
                else
                {
                    vdapath = "Software\\Citrix\\VirtualDesktopAgent";
                }
                try
                {
                    if (Array.Exists(Registry.LocalMachine.OpenSubKey(vdapath).GetValueNames(),
                                     delegate(string s) { return(s.Equals("ListOfDDCs")); }))
                    {
                        xdvdapresent.value = "1";
                    }
                    else
                    {
                        // ListOfDDCs not found
                        xdvdapresent.value = "0";
                    }

                    try
                    {
                        if (Registry.LocalMachine.OpenSubKey(vdapath).GetValueKind("ProductInstalled") == RegistryValueKind.DWord)
                        {
                            try
                            {
                                xdvdaproductinstalled.value = ((int)Registry.LocalMachine.OpenSubKey(vdapath).GetValue("ProductInstalled")).ToString();
                            }
                            catch (Exception e)
                            {
                                wmisession.Log("addXDInfoToStore Can't read ProductInstalled : " + e.ToString());
                            }
                        }
                        else
                        {
                            wmisession.Log("addXDInfoToStore ProductInstalled is not a DWORD");
                        }
                    }
                    catch
                    {
                        //ProductInstalled doesn't exist
                    }
                }
                catch
                {
                    // Unable to read vdapath
                    xdvdapresent.value = "0";
                }
            }
            catch (Exception e)
            {
                wmisession.Log("addXDInfoToStore Failed : " + e.ToString());
            }
        }
Example #3
0
 void getConsoleAndSpawn()
 {
     if (running)
     {
         try {
             session = Win32Impl.WTSGetActiveConsoleSessionId();
             wmisession.Log("New session " + session.ToString());
             if (session != 0xFFFFFFFF)
             {
                 Win32Impl.AcquireSystemPrivilege(Win32Impl.SE_TCB_NAME);
                 consoletoken = Win32Impl.QueryUserToken(session);
                 wmisession.Log("Got new session token");
                 gotConsole = true;
                 spawnWorker();
             }
         }
         catch (Exception e) {
             gotConsole = false;
             WmiBase.Singleton.DebugMsg(e.ToString());
         }
     }
     else
     {
         gotConsole = false;
     }
 }
Example #4
0
 void DumpOsData()
 {
     osname.value      = (string)WmiBase.Singleton.Win32_OperatingSystem["Name"];
     hostname.value    = (string)WmiBase.Singleton.Win32_ComputerSystem["Name"];
     hostnamedns.value = Win32Impl.GetComputerDnsHostname();
     domain.value      = (string)WmiBase.Singleton.Win32_ComputerSystem["Domain"];
 }
Example #5
0
            void getConsoleAndSpawn()
            {
                if (running)
                {
                    try {
                        session = Win32Impl.WTSGetActiveConsoleSessionId();
                        wmisession.Log("New session " + session.ToString());
                        if (session != 0xFFFFFFFF)
                        {
                            wmisession.Log("Checking to see if XenDesktop is active");
                            if (XenAppXenDesktop.ActiveConsoleSession(session))
                            {
                                wmisession.Log("Active XenDesktop session, not spawning worker");
                                gotConsole = false;
                                return;
                            }

                            Win32Impl.AcquireSystemPrivilege(Win32Impl.SE_TCB_NAME);
                            consoletoken = Win32Impl.QueryUserToken(session);
                            wmisession.Log("Got new session token");
                            gotConsole = true;
                            spawnWorker();
                        }
                    }
                    catch (Exception e) {
                        gotConsole = false;
                        WmiBase.Singleton.DebugMsg(e.ToString());
                    }
                }
                else
                {
                    wmisession.Log("Not got console");
                    gotConsole = false;
                }
            }
        override protected void onFeature()
        {
            wmisession.Log("Received shutdown event");
            Win32Impl.AcquireSystemPrivilege(Win32Impl.SE_SHUTDOWN_NAME);


            if (controlKey.Exists())
            {
                string action = controlKey.value;
                wmisession.Log("Received shutdown event type " + controlKey.value);

                try
                {
                    switch (action)
                    {
                    case powerPowerOff:
                        doPowerOff();
                        break;

                    case powerHalt:
                        doPowerOff();
                        break;

                    case powerReboot:
                        doReboot();
                        break;

                    case powerHibernate:
                        controlHibernationState.value = statestarted;
                        controlKey.Remove();
                        if (!Application.SetSuspendState(PowerState.Hibernate, false, false))
                        {
                            controlHibernationState.value = statefailed;
                        }
                        break;

                    case powerS3:
                        controlS3State.value = statestarted;
                        controlKey.Remove();
                        if (!Application.SetSuspendState(PowerState.Suspend, false, false))
                        {
                            controlS3State.value = statefailed;
                        }
                        break;

                    default:
                        // This is a shutdown state we can't handle,
                        // so return without removing the control key
                        return;
                    }
                }
                catch (Exception e)
                {
                    wmisession.Log("Shutdown attempt" + action + " failed:\n" + e.ToString());
                }
                controlKey.Remove();
            }
        }
 public static IntPtr CreateUserProcess(IntPtr consoletoken, string fullpath, string cmdline)
 {
     Win32Impl.STARTUPINFO         si = new Win32Impl.STARTUPINFO();
     Win32Impl.PROCESS_INFORMATION pi = new Win32Impl.PROCESS_INFORMATION();
     if (!Win32Impl.CreateProcessAsUser(consoletoken, fullpath, cmdline, IntPtr.Zero, IntPtr.Zero, false, 0, IntPtr.Zero, IntPtr.Zero, ref si, out pi))
     {
         throw Error("CreateProcessAsUser");
     }
     return(pi.hProcess);
 }
Example #8
0
 public void HandleSessionChange(System.ServiceProcess.SessionChangeReason changeargs, uint sessionId)
 {
     lock (statelock) {
         if (running &&
             (sessionId == Win32Impl.WTSGetActiveConsoleSessionId()))
         {
             state.HandleConsoleChanged(changeargs);
         }
     }
 }
 void doPowerOff()
 {
     try
     {
         Win32Impl.Shutdown();
     }
     catch (Exception e)
     {
         wmisession.Log("Power off failed:\n" + e.ToString());
     }
 }
Example #10
0
 void doReboot()
 {
     try
     {
         Win32Impl.Reboot();
     }
     catch (Exception e)
     {
         wmisession.Log("Reboot failed\n" + e.ToString());
     }
 }
Example #11
0
        List <string> ListXenStoreVolumes()
        {
            List <string> list = new List <string>();

            string[] mountpoints = wmisession.GetXenStoreItem("control/snapshot/volume").children;
            foreach (string mountpoint in mountpoints)
            {
                string name = wmisession.GetXenStoreItem(mountpoint).value;
                try {
                    list.Add(Win32Impl.GetVolumeNameFromMountPoint(name));
                }
                catch {};
            }
            return(list);
        }
Example #12
0
        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());
            }
        }
Example #13
0
 void handleConsoleChanged()
 {
     if (running)
     {
         wmisession.Log("Console changed");
         if (gotConsole == false)
         {
             getConsoleAndSpawn();
         }
         else
         {
             uint newsession = Win32Impl.WTSGetActiveConsoleSessionId();
             wmisession.Log("changed to session " + newsession.ToString());
             if (newsession != session)
             {
                 restartWorker();
             }
         }
     }
 }
Example #14
0
        void resetTime()
        {
            // We need to use FromFileTime to read the xentime stamp into
            // a DateTime object, .net tries to convert it to local
            // time.  So We read it as UTC, then tell .net its already
            // local.
            long internalxentime = (long)WmiBase.Singleton.XenTime;

            if (internalxentime == 0)
            {
                wmisession.Log("unable to reset clock to xentime");
                return;
            }
            DateTime xentime = DateTime.SpecifyKind(
                DateTime.FromFileTimeUtc(internalxentime),
                System.DateTimeKind.Local);

            wmisession.Log("Xentime = " + xentime.ToString());
            // Then set the time, via the Win32 API
            Win32Impl.SYSTEMTIME systime = new Win32Impl.SYSTEMTIME(xentime);
            Win32Impl.SetSystemTime(ref systime);
        }
Example #15
0
            public WorkerProcess(ClipboardAccess clipboard, WmiSession wmisession, IExceptionHandler exceptionhandler, IWorkerProcessHandler wphandler, IntPtr consoletoken)
            {
                this.clipboard        = clipboard;
                this.wmisession       = wmisession;
                this.exceptionhandler = exceptionhandler;
                this.wphandler        = wphandler;

                workerlock = new object();
                try
                {
                    comms = new CommServer(this);
                }
                catch (Exception e)
                {
                    wmisession.Log("Comms server failed to start:" + e.ToString());
                    throw;
                }
                try
                {
                    AddToXDIgnoreApplicationList();
                    string path     = (string)Registry.GetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\Citrix\\XenTools", "Install_Dir", "");
                    string fullpath = string.Format("{0}\\" + Branding.Instance.getString("FILENAME_dpriv"), path);
                    string cmdline  = string.Format(Branding.Instance.getString("FILENAME_dpriv") + " {0}", comms.secret);
                    this.worker            = new SafeWaitHandle(Win32Impl.CreateUserProcess(consoletoken, fullpath, cmdline), true);
                    workerWaiter           = new ProcessWaitHandle(this.worker);
                    registeredWorkerWaiter = ThreadPool.RegisterWaitForSingleObject(workerWaiter, handleWorker, null, Timeout.Infinite, true);
                    this.workerrunning     = true;
                    wmisession.Log("Worker Process spawned");
                }
                catch (Exception e)
                {
                    wmisession.Log("Worker process spawn exception : " + e.ToString());
                    comms.CloseMessagePipes();

                    throw;
                }
            }
Example #16
0
 void closeConsoleToken()
 {
     Win32Impl.Close(this.consoletoken);
 }
Example #17
0
        void SetComputerName()
        {
            wmisession.Log("Set Computer Name Requested");
            state.value = "InProgress";
            String defaultname;
            bool   res;

            try {
                defaultname = name.value;
                name.Remove();
            }
            catch {
                try {
                    wmisession.Log("Setting computer name to default");
                    XenStoreItem name = wmisession.GetXenStoreItem("name");
                    defaultname = name.value;
                }
                catch (Exception e) {
                    wmisession.Log("Unable to read default name for domain from xenstore: " + e.ToString());
                    error.value = "Can't read default computer name";
                    state.value = "Failed";
                    return;
                }
            }

            if (defaultname.Equals(""))
            {
                wmisession.Log("Can't set to empty computer name");
                error.value = "Computer name empty";
                state.value = "Failed";
                return;
            }

            if (defaultname.Length > Win32Impl.MAX_COMPUTERNAME_LENGTH)
            {
                warn.value = "Computer name exceeds MAX_COMPUTERNAME_LENGTH.  The NetBIOS name will be truncated";
            }

            try
            {
                wmisession.Log("Setting computer name to " + defaultname);
                Win32Impl.SetLastError(0);
                res = Win32Impl.SetComputerNameEx(Win32Impl.COMPUTER_NAME_FORMAT.ComputerNamePhysicalDnsHostname, defaultname);
                if (!res)
                {
                    wmisession.Log("Setting computer name failed " + Marshal.GetLastWin32Error().ToString());
                    error.value = "Setting name failed (error code " + Marshal.GetLastWin32Error().ToString() + ")";
                    state.value = "Failed";
                    return;
                }
                wmisession.Log("Setting computer name succceded");
            }
            catch (Exception e)
            {
                wmisession.Log("Exception setting computer name : " + e.ToString());
                error.value = "Exception calling set computer name";
                state.value = "Failed";
                return;
            }
            try
            {
                wmisession.Log("Target hostname " + defaultname);
                wmisession.Log("Current hostname" + Win32Impl.GetComputerDnsHostname());
                if (defaultname.Equals(Win32Impl.GetComputerDnsHostname()))
                {
                    wmisession.Log("No need to reboot to change computer name, already " + defaultname);
                    state.value = "NoChange";
                    return;
                }
            }
            catch {
            }
            state.value = "SucceededNeedsReboot";
        }