├── Create_AboutMyDevice_Service.ps1
├── README.md
├── Remove_AboutMyDevice_Service.ps1
├── Sources
├── AboutMyDevice_Service.ps1
├── AboutMyDevice_Systray.ps1
├── About_this_computer.ps1
├── About_this_computer.xaml
├── Actions_scripts
│ ├── Collect_Logs.ps1
│ ├── Content_to_collect.xml
│ ├── Drivers_Enumerator.ps1
│ ├── Events_Enumerator.ps1
│ ├── HTML_Export_CSS.css
│ ├── KB_Enumerator.ps1
│ ├── List_Large_Files.ps1
│ ├── Services_Enumerator.ps1
│ └── Upload_Logs_Sharepoint.ps1
├── Config
│ ├── Main_Config.xml
│ ├── Sharepoint.xml
│ └── Support.xml
├── Public
│ └── Invoke-AsCurrentUser.ps1
├── Run.ps1
├── RunAsUser.psd1
├── RunAsUser
│ └── 1.5.1
│ │ ├── LICENSE
│ │ ├── New folder
│ │ └── New Microsoft Excel Worksheet.xlsx
│ │ ├── PSGetModuleInfo.xml
│ │ ├── Public
│ │ └── Invoke-AsCurrentUser.ps1
│ │ ├── README.md
│ │ ├── RunAsUser.psd1
│ │ └── runasuser.psm1
├── ServiceUI.exe
├── assembly
│ ├── LiveCharts.Wpf.dll
│ ├── LiveCharts.dll
│ ├── LoadingIndicators.WPF.dll
│ ├── MahApps.Metro.IconPacks.dll
│ ├── MahApps.Metro.dll
│ └── System.Windows.Interactivity.dll
├── depannage.png
├── images
│ ├── Thumbs.db
│ ├── about.ico
│ ├── hdd.png
│ ├── hdd1.png
│ ├── logo.png
│ ├── monitor.png
│ └── support.png
├── menu_pictures
│ ├── exit.png
│ ├── help.png
│ ├── help2.ico
│ ├── log.png
│ ├── portal.png
│ ├── quick_assist.png
│ └── sync2.png
├── nssm.exe
├── resources
│ ├── Icons.xaml
│ └── custom.xaml
└── runasuser.psm1
└── preview.gif
/Create_AboutMyDevice_Service.ps1:
--------------------------------------------------------------------------------
1 | $ProgData = $env:PROGRAMDATA
2 | $Current_Folder = split-path $MyInvocation.MyCommand.Path
3 | $AboutMyDevice_Folder = $env:programdata + "\SD_AboutMyDevice"
4 | $SystemRoot = $env:SystemRoot
5 | $Debug_Folder = "$SystemRoot\Debug"
6 | $Log_File = "$Debug_Folder\SD_AboutMyDevice.log"
7 | $ServiceName = "About my device"
8 | $Service_Description = "A systray tool allowing user to display information about his device, and run some actions"
9 |
10 | Function Write_Log
11 | {
12 | param(
13 | $Message_Type,
14 | $Message
15 | )
16 |
17 | $MyDate = "[{0:MM/dd/yy} {0:HH:mm:ss}]" -f (Get-Date)
18 | Add-Content $Log_File "$MyDate - $Message_Type : $Message"
19 | write-host "$MyDate - $Message_Type : $Message"
20 | }
21 |
22 | Add-content $Log_File ""
23 | If(test-path $AboutMyDevice_Folder){Remove-item $AboutMyDevice_Folder -Recurse -Force}
24 |
25 | Try
26 | {
27 | New-item $AboutMyDevice_Folder -Force -Type directory
28 | If(!(test-path $Log_File)){new-item $Log_File -type file -force}
29 | Write_Log -Message_Type "SUCCESS" -Message "Creating folder: $AboutMyDevice_Folder"
30 | $Create_Folder_Status = $True
31 | }
32 | Catch
33 | {
34 | Write_Log -Message_Type "ERROR" -Message "n error occured while creating folder: $AboutMyDevice_Folder"
35 | $Create_Folder_Status = $False
36 | }
37 |
38 | Add-content $Log_File ""
39 | If($Create_Folder_Status -eq $True)
40 | {
41 | Try
42 | {
43 | copy-item "$Current_Folder\Sources\*" $AboutMyDevice_Folder -Recurse -Force
44 | $Script:Local_Path_NSSM = "$AboutMyDevice_Folder\nssm.exe"
45 | Write_Log -Message_Type "SUCCESS" -Message "Sources files have been copied in: $AboutMyDevice_Folder"
46 | $Files_Copy_Status = $True
47 | }
48 | Catch
49 | {
50 | Write_Log -Message_Type "ERROR" -Message "An error occured while copying files in: $AboutMyDevice_Folder"
51 | $Files_Copy_Status = $False
52 | }
53 | }
54 |
55 | Add-content $Log_File ""
56 | If($Files_Copy_Status -eq $True)
57 | {
58 | $PathPowerShell = (Get-Command Powershell).Source
59 | $PS1_To_Run = "$AboutMyDevice_Folder\AboutMyDevice_Service.ps1"
60 | $ServiceArguments = '-ExecutionPolicy Bypass -NoProfile -File "{0}"' -f $PS1_To_Run
61 | Try
62 | {
63 | & $Local_Path_NSSM install $ServiceName $PathPowerShell $ServiceArguments
64 | sleep 5
65 | Write_Log -Message_Type "SUCCESS" -Message "The service $ServiceName has been successfully created"
66 | $Create_Service_Status = $True
67 | }
68 | Catch
69 | {
70 | Write_Log -Message_Type "ERROR" -Message "An issue occured while creating the service: $ServiceName"
71 | $Create_Service_Status = $False
72 | }
73 | }
74 |
75 | Add-content $Log_File ""
76 | If($Create_Service_Status -eq $True)
77 | {
78 | $PathPowerShell = (Get-Command Powershell).Source
79 | Try
80 | {
81 | & $Local_Path_NSSM start $ServiceName
82 | & $Local_Path_NSSM set $ServiceName description $Service_Description
83 | Write_Log -Message_Type "SUCCESS" -Message "Starting service $ServiceName"
84 | }
85 | Catch
86 | {
87 | Write_Log -Message_Type "ERROR" -Message "An issue occured while starting service $ServiceName"
88 | }
89 | }
90 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # About my device
2 | In this post, I will show you a quick systray tool allowing user to get some informations about the device and run some quick actions
3 |
4 | 
5 |
6 | > *View the full blog post here*
7 | http://www.systanddeploy.com/2020/02/ps1-to-exe-generator-create-exe-for.html
8 |
--------------------------------------------------------------------------------
/Remove_AboutMyDevice_Service.ps1:
--------------------------------------------------------------------------------
1 | $ProgData = $env:PROGRAMDATA
2 | $Current_Folder = split-path $MyInvocation.MyCommand.Path
3 | $AboutMyDevice_Folder = $env:programdata + "\SD_AboutMyDevice"
4 | $SystemRoot = $env:SystemRoot
5 | $Debug_Folder = "$SystemRoot\Debug"
6 | $Log_File = "$Debug_Folder\GRT_AboutMyDevice.log"
7 | $ServiceName = "About my device"
8 |
9 | Function Write_Log
10 | {
11 | param(
12 | $Message_Type,
13 | $Message
14 | )
15 |
16 | $MyDate = "[{0:MM/dd/yy} {0:HH:mm:ss}]" -f (Get-Date)
17 | Add-Content $Log_File "$MyDate - $Message_Type : $Message"
18 | write-host "$MyDate - $Message_Type : $Message"
19 | }
20 |
21 |
22 | Add-content $Log_File ""
23 |
24 | $OD_Process_Status = (gwmi win32_process | Where {$_.commandline -like "*AboutMydevice_Systray*"})
25 | $OD_Process_Status2 = get-process | where {$_.MainWindowTitle -like "*About my device*"}
26 | If($OD_Process_Status -ne $null)
27 | {
28 | $OD_Process_Status.Terminate()
29 | }
30 |
31 | If($OD_Process_Status2 -ne $null)
32 | {
33 | $OD_Process_Status2 | kill -Force
34 | }
35 |
36 | $Script:Local_Path_NSSM = "$AboutMyDevice_Folder\nssm.exe"
37 | $Local_Path_NSSM = "$AboutMyDevice_Folder\nssm.exe"
38 | Get-Service $ServiceName | stop-service
39 | & $Local_Path_NSSM remove $ServiceName confirm
40 | If(test-path $AboutMyDevice_Folder){Remove-item $AboutMyDevice_Folder -Recurse -Force}
41 |
--------------------------------------------------------------------------------
/Sources/AboutMyDevice_Service.ps1:
--------------------------------------------------------------------------------
1 |
2 | $ProgData = $env:PROGRAMDATA
3 | $Current_Folder = split-path $MyInvocation.MyCommand.Path
4 | $AboutMyDevice_Folder = $env:programdata + "\SD_AboutMyDevice"
5 | $SystemRoot = $env:SystemRoot
6 | $Debug_Folder = "$SystemRoot\Debug"
7 | $Log_File = "$AboutMyDevice_Folder\GRT_AboutMyDevice.log"
8 | $ServiceName = "GRTgaz About my device"
9 |
10 | Function Write_Log
11 | {
12 | param(
13 | $Message_Type,
14 | $Message
15 | )
16 |
17 | $MyDate = "[{0:MM/dd/yy} {0:HH:mm:ss}]" -f (Get-Date)
18 | Add-Content $Log_File "$MyDate - $Message_Type : $Message"
19 | write-host "$MyDate - $Message_Type : $Message"
20 | }
21 |
22 | If(!(test-path $Log_File)){new-item $Log_File -type file -force}
23 |
24 | while($true)
25 | {
26 | Add-Content $Log_File ""
27 |
28 | Try
29 | {
30 | import-module "$AboutMyDevice_Folder\RunasUser"
31 | Write_Log -Message_Type "SUCCESS" -Message "Importation du module RunasUser avec succès"
32 | $RunasUser_Module_imported = $True
33 | }
34 | Catch
35 | {
36 | Write_Log -Message_Type "ERROR" -Message "Erreur ^pendant l'importation du module RunasUser"
37 | $RunasUser_Module_imported = $False
38 | }
39 |
40 | If($RunasUser_Module_imported -eq $True)
41 | {
42 | $scriptblock = {
43 | powershell -ExecutionPolicy Bypass -NoProfile "C:\ProgramData\SD_AboutMyDevice\AboutMyDevice_Systray.ps1"
44 | }
45 | Try
46 | {
47 | Write_Log -Message_Type "INFO" -Message "Exécution du script de comparaison en cours"
48 | Invoke-AsCurrentUser -ScriptBlock $scriptblock
49 | Write_Log -Message_Type "SUCCESS" -Message "Exécution du script de comparaison"
50 | }
51 | Catch
52 | {
53 | Write_Log -Message_Type "ERROR" -Message "Erreur pendant l'exécution du script de comparaison"
54 | }
55 | }
56 |
57 | Write_Log -Message_Type "INFO" -Message "The process of checking the $AboutMyDevice_Folder program will be paused for 3 hours"
58 | Add-content $Log_File ""
59 | write-host ""
60 | Start-Sleep -Seconds 10
61 | }
62 |
63 |
--------------------------------------------------------------------------------
/Sources/AboutMyDevice_Systray.ps1:
--------------------------------------------------------------------------------
1 |
2 | $Global:Current_Folder = split-path $MyInvocation.MyCommand.Path
3 |
4 | [System.Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms') | out-null
5 | [System.Reflection.Assembly]::LoadWithPartialName('presentationframework') | out-null
6 | [System.Reflection.Assembly]::LoadWithPartialName('System.Drawing') | out-null
7 | [System.Reflection.Assembly]::LoadWithPartialName('WindowsFormsIntegration') | out-null
8 | [System.Reflection.Assembly]::LoadFrom("$Current_Folder\assembly\MahApps.Metro.dll") | out-null
9 |
10 |
11 | $Log_File = $env:temp + "about_this_comp.log"
12 |
13 | Function Write_Log
14 | {
15 | param(
16 | $Message_Type,
17 | $Message
18 | )
19 |
20 | $MyDate = "[{0:MM/dd/yy} {0:HH:mm:ss}]" -f (Get-Date)
21 | Add-Content $Log_File "$MyDate - $Message_Type : $Message"
22 | write-host "$MyDate - $Message_Type : $Message"
23 | }
24 |
25 | If(!(test-path $Log_File)){new-item $Log_File -type file -force}
26 | $Global:Current_Folder = split-path $MyInvocation.MyCommand.Path
27 |
28 |
29 |
30 | $AboutMyDevice_Folder = $env:programdata + "\SD_AboutMyDevice"
31 | $Systray_Pictures = "$Current_Folder\menu_pictures"
32 |
33 |
34 | # Create object for the systray
35 | $Systray_Tool_Icon = New-Object System.Windows.Forms.NotifyIcon
36 | # Text displayed when you pass the mouse over the systray icon
37 | $Systray_Tool_Icon.Text = "About my device"
38 |
39 | # Systray icon
40 | $Systray_Tool_Icon.Icon = "$Systray_Pictures\help2.ico"
41 | $Systray_Tool_Icon.Visible = $true
42 |
43 | $Get_Support_Infos_Content = [xml](get-content "$current_folder\Config\Main_Config.xml")
44 | $Main_Language = $Get_Support_Infos_Content.Config.Main_Language
45 | $Display_Send_Logs = $Get_Support_Infos_Content.Config.Display_Send_Logs
46 | $Display_Quick_Assist = $Get_Support_Infos_Content.Config.Display_Quick_Assist
47 | $Display_Open_CompanyPortal = $Get_Support_Infos_Content.Config.Display_Open_CompanyPortal
48 | $Display_Sync = $Get_Support_Infos_Content.Config.Display_Sync
49 | $CompanyPortal_SoftwareCenter_Preference = $Get_Support_Infos_Content.Config.CompanyPortal_SoftwareCenter_Preference
50 | $Send_Logs_Method = $Get_Support_Infos_Content.Config.Send_Logs_Method
51 | $Support_Mail = $Get_Support_Infos_Content.Config.Support_Mail
52 |
53 | $contextmenu = New-Object System.Windows.Forms.ContextMenuStrip
54 |
55 |
56 | $Run_Tool = $contextmenu.Items.Add("Display info about my device");
57 | $Run_Tool_Img =[System.Drawing.Bitmap]::FromFile("$Systray_Pictures\help.png")
58 | $Run_Tool.Image = $Run_Tool_Img
59 |
60 |
61 |
62 | If($Display_Quick_Assist -eq "True")
63 | {
64 | $Run_Quick_Assist = $contextmenu.Items.Add("Open Quick Assist");
65 | $Run_Quick_Assist_Img =[System.Drawing.Bitmap]::FromFile("$Systray_Pictures\quick_assist.png")
66 | $Run_Quick_Assist.Image = $Run_Quick_Assist_Img
67 |
68 | $Run_Quick_Assist.add_Click({
69 | & "$env:systemroot\system32\quickassist.exe"
70 | })
71 | }
72 |
73 |
74 | $CompanyPortal_SoftwareCenter_Preference = $Get_Support_Infos_Content.Config.CompanyPortal_SoftwareCenter_Preference
75 |
76 |
77 | If($Display_Open_CompanyPortal -eq "True")
78 | {
79 | If($CompanyPortal_SoftwareCenter_Preference -eq "CompanyPortal")
80 | {
81 | $Run_Portal = $contextmenu.Items.Add("Open Company Portal");
82 | $Run_Portal_Img =[System.Drawing.Bitmap]::FromFile("$Systray_Pictures\portal.png")
83 | $Run_Portal.Image = $Run_Portal_Img
84 |
85 | $Run_Portal.add_Click({
86 | $Get_Appli_Name = (Get-AppxPackage -name Microsoft.CompanyPortal).PackageFamilyName
87 | explorer.exe shell:appsFolder\$Get_Appli_Name!App
88 | })
89 | }
90 | ElseIf($CompanyPortal_SoftwareCenter_Preference -eq "SoftwareCenter")
91 | {
92 | $Run_Portal = $contextmenu.Items.Add("Open Software Center");
93 | $Run_Portal_Img =[System.Drawing.Bitmap]::FromFile("$Systray_Pictures\portal.png")
94 | $Run_Portal.Image = $Run_Portal_Img
95 | $Run_Portal.add_Click({
96 | $Software_Center_Path = "C:\WINDOWS\CCM\ClientUX\SCClient.exe"
97 | If(test-path $Software_Center_Path)
98 | {
99 | start-process $Software_Center_Path
100 | }
101 | })
102 | }
103 | }
104 |
105 | If($Display_Sync -eq "True")
106 | {
107 | $Run_Sync_Device = $contextmenu.Items.Add("Sync my device");
108 | $Run_Sync_Device_Img =[System.Drawing.Bitmap]::FromFile("$Systray_Pictures\sync2.png")
109 | $Run_Sync_Device.Image = $Run_Sync_Device_Img
110 |
111 | $Run_Sync_Device.add_Click({
112 | $Check_Intune_Service = get-service intunemanagementextension -ea silentlycontinue
113 | If($Check_Intune_Service -ne $null)
114 | {
115 | $Shell = New-Object -ComObject Shell.Application
116 | $Shell.open("intunemanagementextension://syncapp")
117 | }
118 |
119 | $Get_MECM_Client_Version = (Get-WMIObject -Namespace root\ccm -Class SMS_Client -ea silentlycontinue).ClientVersion
120 | If($Get_MECM_Client_Version -ne $null)
121 | {
122 | $Client_Actions = @("8EF4D77C","3A88A2F3")
123 | $Config_Manager_Object = New-Object -ComObject CPApplet.CPAppletMgr
124 | ForEach($Action in $Client_Actions)
125 | {
126 | $action_To_Run = $Config_Manager_Object.GetClientActions() | Where-Object {($_.ActionID -like "*$Action*")}
127 | $action_To_Run.PerformAction()
128 | }
129 | }
130 | })
131 | }
132 |
133 | If($Display_Send_Logs -eq "True")
134 | {
135 | $Menu_Logs = $contextmenu.Items.Add("Send device logs to support team");
136 | $Menu_Logs_Img =[System.Drawing.Bitmap]::FromFile("$Systray_Pictures\log.png")
137 | $Menu_Logs.Image = $Menu_Logs_Img
138 |
139 | $Menu_Logs.Add_Click({
140 | If($Send_Logs_Method -eq "Sharepoint")
141 | {
142 | $Get_Sharepoint_Content = [xml](get-content "$current_folder\Config\Sharepoint.xml")
143 | $Sharepoint_Folder = $Get_Sharepoint_Content.Infos.Folder
144 | $Sharepoint_App_ID = $Get_Sharepoint_Content.Infos.App_ID
145 | $Sharepoint_App_Secret = $Get_Sharepoint_Content.Infos.App_Secret
146 | $Sharepoint_Site_URL = $Get_Sharepoint_Content.Infos.Site_URL
147 |
148 | If(($Sharepoint_Folder -ne $null) -and ($Sharepoint_App_ID -ne $null) -and ($Sharepoint_App_Secret -ne $null) -and ($Sharepoint_Site_URL -ne $null))
149 | {
150 | powershell "$current_folder\Actions_scripts\Collect_Logs.ps1"
151 | powershell "$current_folder\Actions_scripts\Upload_Logs_Sharepoint.ps1"
152 | }
153 | }
154 | ElseIf($Send_Logs_Method -eq "Mail")
155 | {
156 | If($Support_Mail -ne $null)
157 | {
158 | powershell "$current_folder\Actions_scripts\Collect_Logs.ps1"
159 | $CompName = $env:computername
160 | # $Logs_Collect_Folder = "C:\Device_Logs_From" + "_$CompName"
161 | $Logs_Collect_Folder = "$env:temp\Device_Logs_From" + "_$CompName"
162 | $Logs_Collect_Folder_ZIP = "$Logs_Collect_Folder" + ".zip"
163 |
164 | $User_Name = $env:USERNAME
165 | $Computer_Name = $env:COMPUTERNAME
166 | $Subject = "Logs sent from $User_Name on device $Computer_Name"
167 | $Body = "Logs sent from $User_Name on device $Computer_Name"
168 | $Outlook = New-Object -ComObject Outlook.Application
169 | $Mail = $Outlook.CreateItem(0)
170 | $Mail.To = $Support_Mail
171 | $mail.Attachments.Add($Logs_Collect_Folder_ZIP)
172 | $Mail.Subject = $Subject
173 | $Mail.Body = $Body
174 | $Mail.Send()
175 | $Outlook.Quit()
176 | [System.Runtime.Interopservices.Marshal]::ReleaseComObject($Outlook) | Out-Null
177 |
178 | # remove-item $Logs_Collect_Folder -Force -Recurse
179 | # remove-item $Logs_Collect_Folder_ZIP -Force
180 | }
181 | }
182 | })
183 | }
184 |
185 | $Menu_Exit = $contextmenu.Items.Add("Exit");
186 | $Menu_Exit_Img=[System.Drawing.Bitmap]::FromFile("$Systray_Pictures\exit.png")
187 | $Menu_Exit.Image = $Menu_Exit_Img
188 |
189 | $Systray_Tool_Icon.ContextMenuStrip = $contextmenu;
190 |
191 |
192 | cd $current_folder
193 |
194 | $Systray_Tool_Icon.Add_Click({
195 | If ($_.Button -eq [Windows.Forms.MouseButtons]::Left) {
196 | powershell -sta .\About_this_computer.ps1
197 | }
198 | })
199 |
200 |
201 | $Run_Tool.Add_Click({
202 | powershell -sta .\About_this_computer.ps1
203 | })
204 |
205 |
206 | # When Exit is clicked, close everything and kill the PowerShell process
207 | $Menu_Exit.add_Click({
208 | $Systray_Tool_Icon.Visible = $false
209 | Stop-Process $pid
210 | })
211 |
212 |
213 |
214 |
215 | # Make PowerShell Disappear
216 | # $windowcode = '[DllImport("user32.dll")] public static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow);'
217 | # $asyncwindow = Add-Type -MemberDefinition $windowcode -name Win32ShowWindowAsync -namespace Win32Functions -PassThru
218 | # $null = $asyncwindow::ShowWindowAsync((Get-Process -PID $pid).MainWindowHandle, 0)
219 |
220 | # Force garbage collection just to start slightly lower RAM usage.
221 | [System.GC]::Collect()
222 |
223 | # Create an application context for it to all run within.
224 | # This helps with responsiveness, especially when clicking Exit.
225 | $appContext = New-Object System.Windows.Forms.ApplicationContext
226 | [void][System.Windows.Forms.Application]::Run($appContext)
--------------------------------------------------------------------------------
/Sources/About_this_computer.ps1:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/damienvanrobaeys/About_my_device/ada9466cff7abb0e991a90c30806291031326b17/Sources/About_this_computer.ps1
--------------------------------------------------------------------------------
/Sources/About_this_computer.xaml:
--------------------------------------------------------------------------------
1 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
136 |
137 |
138 |
139 |
140 |
141 |
142 |
145 |
146 |
147 |
148 |
149 |
150 |
151 |
152 |
153 |
154 |
155 |
156 |
157 |
158 |
159 |
160 |
161 |
162 |
163 |
164 |
165 |
166 |
167 |
168 |
169 |
170 |
171 |
172 |
174 |
175 |
176 |
177 |
178 |
179 |
180 |
181 |
182 |
183 |
184 |
185 |
186 |
187 |
188 |
189 |
190 |
191 |
192 |
193 |
194 |
195 |
196 |
197 |
198 |
199 |
200 |
201 |
202 |
203 |
204 |
205 |
206 |
207 |
208 |
209 |
210 |
211 |
212 |
213 |
214 |
215 |
216 |
217 |
218 |
219 |
220 |
221 |
222 |
223 |
224 |
225 |
226 |
227 |
228 |
229 |
230 |
231 |
232 |
233 |
234 |
235 |
236 |
237 |
238 |
239 |
240 |
241 |
242 |
243 |
244 |
245 |
246 |
247 |
248 |
249 |
250 |
251 |
252 |
253 |
254 |
255 |
256 |
257 |
258 |
259 |
260 |
261 |
262 |
263 |
264 |
265 |
266 |
267 |
268 |
269 |
270 |
271 |
272 |
273 |
274 |
275 |
276 |
277 |
278 |
279 |
280 |
281 |
282 |
283 |
284 |
285 |
286 |
287 |
288 |
289 |
290 |
291 |
292 |
293 |
294 |
295 |
296 |
297 |
298 |
299 |
300 |
301 |
302 |
303 |
304 |
305 |
306 |
307 |
308 |
309 |
310 |
311 |
312 |
313 |
314 |
315 |
316 |
317 |
318 |
319 |
320 |
323 |
324 |
325 |
326 |
327 |
328 |
329 |
330 |
331 |
332 |
333 |
334 |
335 |
336 |
337 |
338 |
339 |
340 |
341 |
342 |
343 |
344 |
345 |
346 |
347 |
348 |
349 |
350 |
351 |
352 |
353 |
354 |
355 |
356 |
357 |
358 |
359 |
360 |
361 |
362 |
363 |
364 |
365 |
366 |
367 |
368 |
369 |
370 |
371 |
372 |
373 |
374 |
375 |
376 |
377 |
378 |
379 |
380 |
381 |
382 |
383 |
384 |
385 |
386 |
387 |
388 |
389 |
390 |
391 |
392 |
393 |
394 |
395 |
396 |
397 |
398 |
399 |
400 |
401 |
402 |
403 |
404 |
405 |
406 |
407 |
408 |
409 |
410 |
411 |
412 |
413 |
414 |
415 |
416 |
417 |
418 |
419 |
420 |
421 |
422 |
423 |
424 |
425 |
426 |
427 |
428 |
429 |
430 |
431 |
432 |
433 |
434 |
435 |
436 |
437 |
438 |
439 |
440 |
441 |
442 |
443 |
444 |
445 |
446 |
447 |
448 |
449 |
450 |
451 |
452 |
453 |
454 |
--------------------------------------------------------------------------------
/Sources/Actions_scripts/Collect_Logs.ps1:
--------------------------------------------------------------------------------
1 | #======================================================================================================================
2 | #
3 | # Script purpose : Collect Intune Device event logs, files and folders, registry keys and upload them on Sharepoint
4 | # Author : Damien VAN ROBAEYS
5 | # Twitter : @syst_and_deploy
6 | # Blog : http://www.systanddeploy.com/
7 | #
8 | #======================================================================================================================
9 |
10 | # ##########################################################################################
11 | # Use this part if you have an external XML for content to collect
12 | # ##########################################################################################
13 |
14 | $Current_Folder = split-path $MyInvocation.MyCommand.Path
15 |
16 |
17 | # ##########################################################################################
18 | # Main variables
19 | # ##########################################################################################
20 |
21 | $SystemRoot = $env:SystemRoot
22 | $CompName = $env:computername
23 |
24 | $Get_Day_Date = Get-Date -Format "yyyyMMdd"
25 | $Log_File = "$env:temp\Collect_Device_Content_$CompName" + "_$Get_Day_Date.log"
26 | # $Log_File = "$SystemRoot\Debug\Collect_Device_Content_$CompName" + "_$Get_Day_Date.log"
27 | # $Logs_Collect_Folder = "C:\Device_Logs_From" + "_$CompName" #+ "_$Get_Day_Date"
28 | $Logs_Collect_Folder = "$env:temp\Device_Logs_From" + "_$CompName" #+ "_$Get_Day_Date"
29 | $Logs_Collect_Folder_ZIP = "$Logs_Collect_Folder" + ".zip"
30 | $EVTX_files = "$Logs_Collect_Folder\EVTX_Files"
31 | $Reg_Export = "$Logs_Collect_Folder\Export_Reg_Values.csv"
32 | $Logs_Folder = "$Logs_Collect_Folder\All_logs"
33 |
34 | $XML_Path = "$Current_Folder\Content_to_collect.xml"
35 | $Content_to_collect_XML = [xml] (Get-Content $XML_Path)
36 | If(!(test-path $Logs_Collect_Folder)){new-item $Logs_Collect_Folder -type Directory -force | out-null}
37 | If(!(test-path $EVTX_files)){new-item $EVTX_files -type Directory -force | out-null}
38 | If(!(test-path $Log_File)){new-item $Log_File -type file -force | out-null}
39 | If(!(test-path $Logs_Folder)){new-item $Logs_Folder -type Directory -force | out-null}
40 |
41 |
42 | # ##########################################################################################
43 | # Main functions
44 | # ##########################################################################################
45 |
46 | Function Write_Log
47 | {
48 | param(
49 | $Message_Type,
50 | $Message
51 | )
52 |
53 | $MyDate = "[{0:MM/dd/yy} {0:HH:mm:ss}]" -f (Get-Date)
54 | Add-Content $Log_File "$MyDate - $Message_Type : $Message"
55 | # write-host "$MyDate - $Message_Type : $Message"
56 | }
57 |
58 | Function Export_Event_Logs
59 | {
60 | param(
61 | $Log_To_Export,
62 | $Log_Output,
63 | $File_Name
64 | )
65 |
66 | Write_Log -Message_Type "INFO" -Message "Collecting logs from: $Log_To_Export"
67 | Try
68 | {
69 | WEVTUtil export-log $Log_To_Export "$Log_Output\$File_Name.evtx" | out-null
70 | Write_Log -Message_Type "SUCCESS" -Message "Event log $File_Name.evtx has been successfully exported"
71 | }
72 | Catch
73 | {
74 | Write_Log -Message_Type "ERROR" -Message "An issue occured while exporting event log $File_Name.evtx"
75 | }
76 | }
77 |
78 |
79 | Function Export_Logs_Files_Folders
80 | {
81 | param(
82 | $Log_To_Export,
83 | $Log_Output
84 | )
85 |
86 | If(test-path $Log_To_Export)
87 | {
88 | $Content_Name = Get-Item $Log_To_Export
89 | Try
90 | {
91 | Copy-Item $Log_To_Export $Log_Output -Recurse -Force
92 | Write_Log -Message_Type "SUCCESS" -Message "The folder $Content_Name has been successfully copied"
93 | }
94 | Catch
95 | {
96 | Write_Log -Message_Type "ERROR" -Message "An issue occured while copying the folder $Content_Name"
97 | }
98 | }
99 | Else
100 | {
101 | Write_Log -Message_Type "ERROR" -Message "The following path does not exist: $Log_To_Export"
102 | }
103 | }
104 |
105 |
106 | Function Export_Registry_Values
107 | {
108 | param(
109 | $Reg_Path,
110 | $Reg_Specific_Value,
111 | $Output_Path
112 | )
113 |
114 | If(test-path "registry::$Reg_Path")
115 | {
116 | $Reg_Array = @()
117 | $Get_Reg_Values = Get-ItemProperty -path registry::$Reg_Path
118 | If($Reg_Specific_Value)
119 | {
120 | $List_Values = $Get_Reg_Values.$Reg_Specific_Value
121 | $Get_Reg_Values_Array = New-Object PSObject
122 | $Get_Reg_Values_Array = $Get_Reg_Values_Array | Add-Member NoteProperty Name $Reg_Specific_Value -passthru
123 | $Get_Reg_Values_Array = $Get_Reg_Values_Array | Add-Member NoteProperty Value $List_Values -passthru
124 | $Get_Reg_Values_Array = $Get_Reg_Values_Array | Add-Member NoteProperty Reg_Path $Reg_Path -passthru
125 | }
126 | Else
127 | {
128 | $List_Values = $Get_Reg_Values.psobject.properties | select name, value | Where-Object {($_.name -ne "PSPath" -and $_.name -ne "PSParentPath" -and $_.name -ne "PSChildName" -and $_.name -ne "PSProvider")}
129 | $Get_Reg_Values_Array = New-Object PSObject
130 | $Get_Reg_Values_Array = $List_Values
131 | $Get_Reg_Values_Array = $Get_Reg_Values_Array | Add-Member NoteProperty Reg_Path $Reg_Path -passthru
132 | }
133 |
134 | $Reg_Array += $Get_Reg_Values_Array
135 |
136 | If(!(test-path $Output_Path))
137 | {
138 | Try
139 | {
140 | $Reg_Array | export-csv $Output_Path -notype
141 | Write_Log -Message_Type "SUCCESS" -Message "Registry values from $Reg_Path have been successfully exported"
142 | }
143 | Catch
144 | {
145 | Write_Log -Message_Type "ERROR" -Message "An issue occured while exporting registry values from $Reg_Path"
146 | }
147 | }
148 | Else
149 | {
150 | Try
151 | {
152 | $Reg_Array | export-csv -Append $Output_Path -notype
153 | Write_Log -Message_Type "SUCCESS" -Message "Registry values from $Reg_Path have been successfully exported"
154 | }
155 | Catch
156 | {
157 | Write_Log -Message_Type "ERROR" -Message "An issue occured while exporting registry values from $Reg_Path"
158 | }
159 | }
160 | }
161 | Else
162 | {
163 | Write_Log -Message_Type "ERROR" -Message "The following REG path does not exist: $Reg_Path"
164 | }
165 | }
166 |
167 |
168 |
169 | # ##########################################################################################
170 | # Main code
171 | # ##########################################################################################
172 |
173 | Write_Log -Message_Type "INFO" -Message "Starting collecting Intune logs on $CompName"
174 |
175 | Add-content $Log_File ""
176 | Add-content $Log_File "---------------------------------------------------------------------------------------------------------"
177 | Write_Log -Message_Type "INFO" -Message "Step 1 - Collecting event logs"
178 | Add-content $Log_File "---------------------------------------------------------------------------------------------------------"
179 | $Events_To_Check = $Content_to_collect_XML.Content_to_collect.Event_Logs.Event_Log
180 | ForEach($Event in $Events_To_Check)
181 | {
182 | $Event_Name = $Event.Event_Name
183 | $Event_Path = $Event.Event_Path
184 | Export_Event_Logs -Log_To_Export $Event_Path -Log_Output $EVTX_files -File_Name $Event_Name
185 | }
186 |
187 |
188 | Add-content $Log_File ""
189 | Add-content $Log_File "---------------------------------------------------------------------------------------------------------"
190 | Write_Log -Message_Type "INFO" -Message "Step 2 - Copying files and folders"
191 | Add-content $Log_File "---------------------------------------------------------------------------------------------------------"
192 | $Folder_To_Check = $Content_to_collect_XML.Content_to_collect.Folders.Folder_Path
193 | ForEach($Explorer_Content in $Folder_To_Check)
194 | {
195 | Export_Logs_Files_Folders -Log_To_Export $Explorer_Content -Log_Output $Logs_Folder
196 | }
197 |
198 |
199 | Add-content $Log_File ""
200 | Add-content $Log_File "---------------------------------------------------------------------------------------------------------"
201 | Write_Log -Message_Type "INFO" -Message "Step 3 - Collecting registry keys"
202 | Add-content $Log_File "---------------------------------------------------------------------------------------------------------"
203 | $Reg_Keys_To_Check = $Content_to_collect_XML.Content_to_collect.Reg_Keys.Reg_Key
204 | ForEach($Reg in $Reg_Keys_To_Check)
205 | {
206 | $Get_Reg_Path = $Reg.Reg_Path
207 | $Get_Reg_Specific_Value = $Reg.Reg_Specific_Value
208 | If($Get_Reg_Specific_Value -ne $null)
209 | {
210 | Export_Registry_Values -Reg_Path $Get_Reg_Path -Reg_Specific_Value $Get_Reg_Specific_Value -Output_Path $Reg_Export
211 | }
212 | Else
213 | {
214 | Export_Registry_Values -Reg_Path $Get_Reg_Path -Output_Path $Reg_Export
215 | }
216 | }
217 |
218 |
219 | Add-content $Log_File ""
220 | Add-content $Log_File "---------------------------------------------------------------------------------------------------------"
221 | Write_Log -Message_Type "INFO" -Message "Step 4 - Creating the ZIP with logs"
222 | Add-content $Log_File "---------------------------------------------------------------------------------------------------------"
223 | Try
224 | {
225 | Add-Type -assembly "system.io.compression.filesystem"
226 | [io.compression.zipfile]::CreateFromDirectory($Logs_Collect_Folder, $Logs_Collect_Folder_ZIP)
227 | Write_Log -Message_Type "SUCCESS" -Message "The ZIP file has been successfully created"
228 | Write_Log -Message_Type "INFO" -Message "The ZIP is located in :$Logs_Collect_Folder_ZIP"
229 | }
230 | Catch
231 | {
232 | Write_Log -Message_Type "ERROR" -Message "An issue occured while creating the ZIP file"
233 | }
234 |
--------------------------------------------------------------------------------
/Sources/Actions_scripts/Content_to_collect.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | C:\ProgramData\Microsoft\IntuneManagementExtension
4 | C:\Windows\debug
5 | C:\Windows\Logs
6 | C:\Windows\ccmsetup
7 | C:\Windows\Panther
8 | C:\Windows\Minidump
9 |
10 |
11 |
12 | System
13 | System
14 |
15 |
16 | Application
17 | Application
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/Sources/Actions_scripts/Drivers_Enumerator.ps1:
--------------------------------------------------------------------------------
1 | #***************************************************************************************************************
2 | # Author: Damien VAN ROBAEYS
3 | # Date: 11/04/2016
4 | # Website: http://www.systanddeploy.com
5 | # Twitter: https://twitter.com/syst_and_deploy
6 | #***************************************************************************************************************
7 |
8 | # ***********************************************************************
9 | # Variables initialization
10 | # ***********************************************************************
11 | $Temp = $env:temp
12 | $ProgData = $env:PROGRAMDATA
13 | $ComputerName = gc env:computername
14 | $Date = get-date
15 | $HTML_Drivers = "$temp\Drivers_List.html"
16 | # $HTML_Drivers = "$temp\OEM_Support\Drivers_List.html"
17 | $Global:Current_Folder =(get-location).path
18 | # $CSS_File = "$temp\OEM_Support\Actions_Scripts\HTML_Export_CSS.css" # CSS for HTML Export
19 | $CSS_File = "$ProgData\OEM_Support\Actions_Scripts\HTML_Export_CSS.css" # CSS for HTML Export
20 |
21 | $Title = "
Drivers list on $ComputerName
This document has been updated on $Date
"
22 |
23 | $Drivers_list_b = gwmi Win32_PnPSignedDriver |
24 | Select-Object devicename, manufacturer, driverversion, infname, IsSigned |
25 | where-object {$_.devicename -ne $null -and $_.infname -ne $null} | sort-object devicename -Unique | ConvertTo-HTML -Fragment
26 |
27 | $Drivers_list = $Drivers_list + $Drivers_list_b
28 |
29 | ConvertTo-HTML -body " $Title
$Drivers_list" -CSSUri $CSS_File |
30 | Out-File -encoding ASCII $HTML_Drivers
31 |
32 |
--------------------------------------------------------------------------------
/Sources/Actions_scripts/Events_Enumerator.ps1:
--------------------------------------------------------------------------------
1 | #***************************************************************************************************************
2 | # Author: Damien VAN ROBAEYS
3 | # Date: 11/04/2016
4 | # Website: http://www.systanddeploy.com
5 | # Twitter: https://twitter.com/syst_and_deploy
6 | #***************************************************************************************************************
7 |
8 |
9 | # ***********************************************************************
10 | # Variables initialization
11 | # ***********************************************************************
12 | $Temp = $env:temp
13 | $ProgData = $env:PROGRAMDATA
14 | $ComputerName = gc env:computername
15 | $All_System_Error = get-eventlog System | where {$_.EntryType -eq "Error"} | select timegenerated, source, eventid, message
16 | $All_Apps_Error = get-eventlog Application | where {$_.EntryType -eq "Error"} | select timegenerated, source, eventid, message
17 |
18 | $Date = get-date
19 | # $HTML_Events = "$Temp\OEM_Support\Events_List.html"
20 | $HTML_Events = "$Temp\Events_List.html"
21 | # $CSS_File = "$temp\OEM_Support\Actions_Scripts\HTML_Export_CSS.css" # CSS for HTML Export
22 | $CSS_File = "$ProgData\OEM_Support\Actions_Scripts\HTML_Export_CSS.css" # CSS for HTML Export
23 |
24 | # *************************************************************************************************
25 |
26 | $Title = "Last applications and system errors on $ComputerName
This document has been updated on $Date
"
27 |
28 | $System_Events = "Last 10 system errors
"
29 | $System_Events_b = $All_System_Error | select -first 10 | % { New-Object psobject -Property @{
30 | Date= $_."timegenerated"
31 | Source=$_."source"
32 | Event_ID = $_."eventid"
33 | Issue=$_."message"
34 | }} | select Date, Source, Event_ID, Issue | ConvertTo-HTML -Fragment
35 |
36 | $System_Events = $System_Events + $System_Events_b
37 |
38 | $Apps_Events = "Last 10 application errors
"
39 | $Apps_Events_b = $All_Apps_Error | select -first 10 | % { New-Object psobject -Property @{
40 | Date= $_."timegenerated"
41 | Source=$_."source"
42 | Event_ID = $_."eventid"
43 | Issue=$_."message"
44 | }} | select Date, Source, Event_ID, Issue | ConvertTo-HTML -Fragment
45 |
46 | $Apps_Events = $Apps_Events + $Apps_Events_b
47 |
48 | ConvertTo-HTML -body " $Title
$System_Events
$Apps_Events" -CSSUri $CSS_File |
49 | Out-File -encoding ASCII $HTML_Events
50 |
51 | # *************************************************************************************************
52 |
53 |
54 |
--------------------------------------------------------------------------------
/Sources/Actions_scripts/HTML_Export_CSS.css:
--------------------------------------------------------------------------------
1 | body
2 | {
3 | font-family: Arial;
4 | font-size: 8pt;
5 | }
6 |
7 | table
8 | {
9 | border: 0px solid #e3e3e3;
10 | border-collapse: collapse;
11 | }
12 |
13 | tr:nth-child(even)
14 | {
15 | background: #f5f5f5;
16 | }
17 |
18 | tr:nth-child(odd)
19 | {
20 | background: #f1f1f1;
21 | }
22 |
23 |
24 | th, td
25 | {
26 | padding: 7px;
27 | }
28 |
29 |
30 | .noBorder {
31 | border:none !important;
32 | }
33 |
34 | tr:hover
35 | {
36 | background:#A1E5DC;
37 | }
38 |
39 | tr
40 | {
41 | -webkit-transition: color 1s ease;
42 | -ms-transition: color 1s ease;
43 | -moz-transition: color 1s ease;
44 | -o-transition: color 1s ease;
45 | }
46 |
47 |
48 | th
49 | {
50 | padding: 3px;
51 | background: #2b5797;
52 | color: white;
53 | font-size: 13px;
54 | text-align:center;
55 | border: 1px solid #e3e3e3;
56 | }
57 |
58 |
59 | td
60 | {
61 | border: 1px solid #e3e3e3;
62 | padding: 5px;
63 | font-size: 11px;
64 | text-align:left;
65 | }
66 |
67 |
68 | .New_object
69 | {
70 | color:#01B0F0;
71 | font-weight:bold;
72 | font-size:17px;
73 | }
74 |
75 | .running
76 | {
77 | color: green;
78 | font-weight:bold;
79 |
80 | }
81 |
82 | .stopped
83 | {
84 | color: red;
85 | font-weight:bold;
86 |
87 | }
88 |
89 | .checkname
90 | {
91 | font-weight: bold;
92 | }
93 | .rowOne
94 | {
95 | background: #f5f5f5;
96 | }
97 | .rowTwo
98 | {
99 | background: #f1f1f1
100 | }
101 | .conform
102 | {
103 | color: green;
104 | text-align: center;
105 | }
106 | .notconform
107 | {
108 | color: red;
109 | text-align: center;
110 | }
111 |
112 | .titre_list
113 | {
114 | color: #2d89ef;
115 | font-weight:bold;
116 | font-size:16pt;
117 | font-family: Segoe UI light, Arial;
118 | }
119 |
120 | .subtitle
121 | {
122 | font-family: Segoe UI Light, Arial;
123 | font-weight:bold;
124 | font-size: 11pt;
125 | color:#00a300;
126 | }
127 |
128 |
129 |
--------------------------------------------------------------------------------
/Sources/Actions_scripts/KB_Enumerator.ps1:
--------------------------------------------------------------------------------
1 | #***************************************************************************************************************
2 | # Author: Damien VAN ROBAEYS
3 | # Date: 11/04/2016
4 | # Website: http://www.systanddeploy.com
5 | # Twitter: https://twitter.com/syst_and_deploy
6 | #***************************************************************************************************************
7 |
8 | # ***********************************************************************
9 | # Variables initialization
10 | # ***********************************************************************
11 | $Temp = $env:temp
12 | $ProgData = $env:PROGRAMDATA
13 | $ComputerName = gc env:computername
14 | $HotfixCount = (Get-wmiobject win32_quickfixengineering | measure-object).count
15 | $Date = get-date
16 | $HTML_Hotfix = "$Temp\hotfixes.html"
17 | $CSS_File = "$ProgData\OEM_Support\Actions_Scripts\HTML_Export_CSS.css" # CSS for HTML Export
18 |
19 | # *************************************************************************************************
20 |
21 | # $Title = "Last applications and system errors on $ComputerName
This document has been updated on $Date
"
22 |
23 | $Title = "Hotfix list on $ComputerName
$HotfixCount are installed on $Date
"
24 |
25 |
26 | $Hotfix_list = Get-wmiobject win32_quickfixengineering |
27 | Select-Object hotfixid, Description, Caption, InstalledOn | Sort-Object InstalledOn | ConvertTo-HTML -Fragment
28 |
29 | # $Hotfix_list = $Hotfix_list + $Hotfix_list_b
30 |
31 | ConvertTo-HTML -body " $Title
$Hotfix_list" -CSSUri $CSS_File |
32 | Out-File -encoding ASCII $HTML_Hotfix
33 |
34 |
35 | # *************************************************************************************************
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/Sources/Actions_scripts/List_Large_Files.ps1:
--------------------------------------------------------------------------------
1 | $Get_Large_Files = gci c:\ -recurse -ea silentlycontinue | sort -descending -property length | select -first 10 name, length, fullname
2 | $Get_Large_Files | out-file "$env:temp\Large_Files.txt"
3 | invoke-item "$env:temp\Large_Files.txt"
--------------------------------------------------------------------------------
/Sources/Actions_scripts/Services_Enumerator.ps1:
--------------------------------------------------------------------------------
1 | #***************************************************************************************************************
2 | # Author: Damien VAN ROBAEYS
3 | # Date: 11/04/2016
4 | # Website: http://www.systanddeploy.com
5 | # Twitter: https://twitter.com/syst_and_deploy
6 | #***************************************************************************************************************
7 |
8 | # ***********************************************************************
9 | # Variables initialization
10 | # ***********************************************************************
11 | $Temp = $env:temp
12 | $ProgData = $env:PROGRAMDATA
13 | $ComputerName = gc env:computername
14 | $Date = get-date
15 | # $HTML_Services = "$Temp\OEM_Support\Services_List.html"
16 | $HTML_Services = "$Temp\Services_List.html"
17 | $CSS_File = "$ProgData\OEM_Support\Actions_Scripts\HTML_Export_CSS.css" # CSS for HTML Export
18 |
19 | # *************************************************************************************************
20 | $Title = "Drivers list on $ComputerName
This document has been updated on $Date
"
21 |
22 | $services_list_b = Get-wmiobject win32_service |
23 | Select-Object Name, Caption, State, Startmode | ConvertTo-HTML -Fragment
24 |
25 | $colorTagTable = @{Stopped = ' class="stopped">Stopped<';
26 | Running = ' class="running">Running<'}
27 |
28 | $services_list = $services_list + $services_list_b
29 |
30 | $colorTagTable.Keys | foreach { $services_list = $services_list -replace ">$_<",($colorTagTable.$_) }
31 |
32 | ConvertTo-HTML -body " $Title
$services_list" -CSSUri $CSS_File |
33 | Out-File -encoding ASCII $HTML_Services
34 |
35 | # *************************************************************************************************
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
--------------------------------------------------------------------------------
/Sources/Actions_scripts/Upload_Logs_Sharepoint.ps1:
--------------------------------------------------------------------------------
1 | $Get_Sharepoint_Content = [xml](get-content ".\Config\Sharepoint.xml")
2 | $Sharepoint_App_ID = $Get_Sharepoint_Content.Infos.App_ID
3 | $Sharepoint_App_Secret = $Get_Sharepoint_Content.Infos.App_Secret
4 | $Sharepoint_Folder = $Get_Sharepoint_Content.Infos.Folder
5 | $Sharepoint_Site_URL = $Get_Sharepoint_Content.Infos.Site_URL
6 |
7 | $CompName = $env:computername
8 | $Logs_Collect_Folder = "$env:temp\Device_Logs_From" + "_$CompName"
9 | $Logs_Collect_Folder_ZIP = "$Logs_Collect_Folder" + ".zip"
10 |
11 | $Is_Nuget_Installed = $False
12 | If(!(Get-PackageProvider | where {$_.Name -eq "Nuget"}))
13 | {
14 | Try
15 | {
16 | [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
17 | Install-PackageProvider -Name Nuget -MinimumVersion 2.8.5.201 -Force -Confirm:$False | out-null
18 | $Is_Nuget_Installed = $True
19 | }
20 | Catch
21 | {
22 | Break
23 | }
24 | }
25 | Else
26 | {
27 | $Is_Nuget_Installed = $True
28 | }
29 |
30 | If($Is_Nuget_Installed -eq $True)
31 | {
32 | $Script:PnP_Module_Status = $False
33 | $Module_Name = "PnP.PowerShell"
34 | If (!(Get-InstalledModule $Module_Name -ErrorAction silentlycontinue))
35 | {
36 | Install-Module $Module_Name -Force -Confirm:$False -ErrorAction SilentlyContinue | out-null
37 | $Module_Version = (Get-Module $Module_Name -listavailable).version
38 | $PnP_Module_Status = $True
39 | }
40 | Else
41 | {
42 | Import-Module $Module_Name -Force -ErrorAction SilentlyContinue
43 | $PnP_Module_Status = $True
44 | }
45 | }
46 |
47 | If($PnP_Module_Status -eq $True)
48 | {
49 | Try
50 | {
51 | Connect-PnPOnline -Url $Sharepoint_Site_URL -ClientID $Sharepoint_App_ID -ClientSecret $Sharepoint_App_Secret
52 | $Sharepoint_Status = "OK"
53 | }
54 | Catch
55 | {
56 | $Sharepoint_Status = "KO"
57 | }
58 |
59 | If($Sharepoint_Status -eq "OK")
60 | {
61 |
62 | Add-PnPFile -Path $Logs_Collect_Folder_ZIP -Folder $Sharepoint_Folder #| out-null
63 | }
64 | }
--------------------------------------------------------------------------------
/Sources/Config/Main_Config.xml:
--------------------------------------------------------------------------------
1 |
2 | Cyan
3 | logo.png
4 |
5 | 3
6 | True
7 | True
8 | True
9 | True
10 | CompanyPortal
11 | Mail
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/Sources/Config/Sharepoint.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/Sources/Config/Support.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | 00 00 00 00 00
7 |
8 |
9 |
--------------------------------------------------------------------------------
/Sources/Public/Invoke-AsCurrentUser.ps1:
--------------------------------------------------------------------------------
1 | function Invoke-AsCurrentUser {
2 | [CmdletBinding()]
3 | param (
4 | [Parameter(Mandatory = $true)]
5 | [scriptblock]
6 | $ScriptBlock,
7 | [Parameter(Mandatory = $false)]
8 | [switch]$NoWait
9 | )
10 | if (!("RunAsUser.ProcessExtensions" -as [type])) {
11 | Add-Type -TypeDefinition $script:source -Language CSharp
12 | }
13 | $encodedcommand = [Convert]::ToBase64String([System.Text.Encoding]::Unicode.GetBytes($ScriptBlock))
14 | $privs = whoami /priv /fo csv | ConvertFrom-Csv | Where-Object { $_.'Privilege Name' -eq 'SeDelegateSessionUserImpersonatePrivilege' }
15 | if ($privs.State -eq "Disabled") {
16 | Write-Error -Message "Not running with correct privilege. You must run this script as system or have the SeDelegateSessionUserImpersonatePrivilege token."
17 | return
18 | }
19 | else {
20 | try {
21 | # Use the same PowerShell executable as the one that invoked the function
22 | $pwshPath = (Get-Process -Id $pid).Path
23 | if ($NoWait) { $ProcWaitTime = 1 } else { $ProcWaitTime = -1 }
24 | [RunAsUser.ProcessExtensions]::StartProcessAsCurrentUser(
25 | $pwshPath, "`"$pwshPath`" -ExecutionPolicy Bypass -Window Normal -EncodedCommand $($encodedcommand)",
26 | (Split-Path $pwshPath -Parent), $false,$ProcWaitTime)
27 | } catch {
28 | Write-Error -Message "Could not execute as currently logged on user: $($_.Exception.Message)" -Exception $_.Exception
29 | return
30 | }
31 | }
32 | }
--------------------------------------------------------------------------------
/Sources/Run.ps1:
--------------------------------------------------------------------------------
1 | cd "C:\ProgramData\GRT_AboutMyDevice"
2 | start-process -WindowStyle hidden powershell.exe "C:\ProgramData\GRT_AboutMyDevice\About_this_computer.ps1"
--------------------------------------------------------------------------------
/Sources/RunAsUser.psd1:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/damienvanrobaeys/About_my_device/ada9466cff7abb0e991a90c30806291031326b17/Sources/RunAsUser.psd1
--------------------------------------------------------------------------------
/Sources/RunAsUser/1.5.1/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2020 Kelvin Tegelaar
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/Sources/RunAsUser/1.5.1/New folder/New Microsoft Excel Worksheet.xlsx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/damienvanrobaeys/About_my_device/ada9466cff7abb0e991a90c30806291031326b17/Sources/RunAsUser/1.5.1/New folder/New Microsoft Excel Worksheet.xlsx
--------------------------------------------------------------------------------
/Sources/RunAsUser/1.5.1/PSGetModuleInfo.xml:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/damienvanrobaeys/About_my_device/ada9466cff7abb0e991a90c30806291031326b17/Sources/RunAsUser/1.5.1/PSGetModuleInfo.xml
--------------------------------------------------------------------------------
/Sources/RunAsUser/1.5.1/Public/Invoke-AsCurrentUser.ps1:
--------------------------------------------------------------------------------
1 | function Invoke-AsCurrentUser {
2 | [CmdletBinding()]
3 | param (
4 | [Parameter(Mandatory = $true)]
5 | [scriptblock]
6 | $ScriptBlock,
7 | [Parameter(Mandatory = $false)]
8 | [switch]$NoWait
9 | )
10 | if (!("RunAsUser.ProcessExtensions" -as [type])) {
11 | Add-Type -TypeDefinition $script:source -Language CSharp
12 | }
13 | $encodedcommand = [Convert]::ToBase64String([System.Text.Encoding]::Unicode.GetBytes($ScriptBlock))
14 | $privs = whoami /priv /fo csv | ConvertFrom-Csv | Where-Object { $_.'Privilege Name' -eq 'SeDelegateSessionUserImpersonatePrivilege' }
15 | if ($privs.State -eq "Disabled") {
16 | Write-Error -Message "Not running with correct privilege. You must run this script as system or have the SeDelegateSessionUserImpersonatePrivilege token."
17 | return
18 | }
19 | else {
20 | try {
21 | # Use the same PowerShell executable as the one that invoked the function
22 | $pwshPath = (Get-Process -Id $pid).Path
23 | if ($NoWait) { $ProcWaitTime = 1 } else { $ProcWaitTime = -1 }
24 | [RunAsUser.ProcessExtensions]::StartProcessAsCurrentUser(
25 | $pwshPath, "`"$pwshPath`" -ExecutionPolicy Bypass -Window Normal -EncodedCommand $($encodedcommand)",
26 | (Split-Path $pwshPath -Parent), $false,$ProcWaitTime)
27 | } catch {
28 | Write-Error -Message "Could not execute as currently logged on user: $($_.Exception.Message)" -Exception $_.Exception
29 | return
30 | }
31 | }
32 | }
--------------------------------------------------------------------------------
/Sources/RunAsUser/1.5.1/README.md:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/damienvanrobaeys/About_my_device/ada9466cff7abb0e991a90c30806291031326b17/Sources/RunAsUser/1.5.1/README.md
--------------------------------------------------------------------------------
/Sources/RunAsUser/1.5.1/RunAsUser.psd1:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/damienvanrobaeys/About_my_device/ada9466cff7abb0e991a90c30806291031326b17/Sources/RunAsUser/1.5.1/RunAsUser.psd1
--------------------------------------------------------------------------------
/Sources/RunAsUser/1.5.1/runasuser.psm1:
--------------------------------------------------------------------------------
1 | $script:source = @"
2 | using Microsoft.Win32.SafeHandles;
3 | using System;
4 | using System.Runtime.InteropServices;
5 | using System.Text;
6 |
7 | namespace RunAsUser
8 | {
9 | internal class NativeHelpers
10 | {
11 | [StructLayout(LayoutKind.Sequential)]
12 | public struct PROCESS_INFORMATION
13 | {
14 | public IntPtr hProcess;
15 | public IntPtr hThread;
16 | public int dwProcessId;
17 | public int dwThreadId;
18 | }
19 |
20 | [StructLayout(LayoutKind.Sequential)]
21 | public struct STARTUPINFO
22 | {
23 | public int cb;
24 | public String lpReserved;
25 | public String lpDesktop;
26 | public String lpTitle;
27 | public uint dwX;
28 | public uint dwY;
29 | public uint dwXSize;
30 | public uint dwYSize;
31 | public uint dwXCountChars;
32 | public uint dwYCountChars;
33 | public uint dwFillAttribute;
34 | public uint dwFlags;
35 | public short wShowWindow;
36 | public short cbReserved2;
37 | public IntPtr lpReserved2;
38 | public IntPtr hStdInput;
39 | public IntPtr hStdOutput;
40 | public IntPtr hStdError;
41 | }
42 |
43 | [StructLayout(LayoutKind.Sequential)]
44 | public struct WTS_SESSION_INFO
45 | {
46 | public readonly UInt32 SessionID;
47 |
48 | [MarshalAs(UnmanagedType.LPStr)]
49 | public readonly String pWinStationName;
50 |
51 | public readonly WTS_CONNECTSTATE_CLASS State;
52 | }
53 | }
54 |
55 | internal class NativeMethods
56 | {
57 | [DllImport("kernel32", SetLastError=true)]
58 | public static extern int WaitForSingleObject(
59 | IntPtr hHandle,
60 | int dwMilliseconds);
61 |
62 | [DllImport("kernel32.dll", SetLastError = true)]
63 | public static extern bool CloseHandle(
64 | IntPtr hSnapshot);
65 |
66 | [DllImport("userenv.dll", SetLastError = true)]
67 | public static extern bool CreateEnvironmentBlock(
68 | ref IntPtr lpEnvironment,
69 | SafeHandle hToken,
70 | bool bInherit);
71 |
72 | [DllImport("advapi32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
73 | public static extern bool CreateProcessAsUserW(
74 | SafeHandle hToken,
75 | String lpApplicationName,
76 | StringBuilder lpCommandLine,
77 | IntPtr lpProcessAttributes,
78 | IntPtr lpThreadAttributes,
79 | bool bInheritHandle,
80 | uint dwCreationFlags,
81 | IntPtr lpEnvironment,
82 | String lpCurrentDirectory,
83 | ref NativeHelpers.STARTUPINFO lpStartupInfo,
84 | out NativeHelpers.PROCESS_INFORMATION lpProcessInformation);
85 |
86 | [DllImport("userenv.dll", SetLastError = true)]
87 | [return: MarshalAs(UnmanagedType.Bool)]
88 | public static extern bool DestroyEnvironmentBlock(
89 | IntPtr lpEnvironment);
90 |
91 | [DllImport("advapi32.dll", SetLastError = true)]
92 | public static extern bool DuplicateTokenEx(
93 | SafeHandle ExistingTokenHandle,
94 | uint dwDesiredAccess,
95 | IntPtr lpThreadAttributes,
96 | SECURITY_IMPERSONATION_LEVEL ImpersonationLevel,
97 | TOKEN_TYPE TokenType,
98 | out SafeNativeHandle DuplicateTokenHandle);
99 |
100 | [DllImport("advapi32.dll", SetLastError = true)]
101 | public static extern bool GetTokenInformation(
102 | SafeHandle TokenHandle,
103 | uint TokenInformationClass,
104 | SafeMemoryBuffer TokenInformation,
105 | int TokenInformationLength,
106 | out int ReturnLength);
107 |
108 | [DllImport("wtsapi32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
109 | public static extern bool WTSEnumerateSessions(
110 | IntPtr hServer,
111 | int Reserved,
112 | int Version,
113 | ref IntPtr ppSessionInfo,
114 | ref int pCount);
115 |
116 | [DllImport("wtsapi32.dll")]
117 | public static extern void WTSFreeMemory(
118 | IntPtr pMemory);
119 |
120 | [DllImport("kernel32.dll")]
121 | public static extern uint WTSGetActiveConsoleSessionId();
122 |
123 | [DllImport("Wtsapi32.dll", SetLastError = true)]
124 | public static extern bool WTSQueryUserToken(
125 | uint SessionId,
126 | out SafeNativeHandle phToken);
127 | }
128 |
129 | internal class SafeMemoryBuffer : SafeHandleZeroOrMinusOneIsInvalid
130 | {
131 | public SafeMemoryBuffer(int cb) : base(true)
132 | {
133 | base.SetHandle(Marshal.AllocHGlobal(cb));
134 | }
135 | public SafeMemoryBuffer(IntPtr handle) : base(true)
136 | {
137 | base.SetHandle(handle);
138 | }
139 |
140 | protected override bool ReleaseHandle()
141 | {
142 | Marshal.FreeHGlobal(handle);
143 | return true;
144 | }
145 | }
146 |
147 | internal class SafeNativeHandle : SafeHandleZeroOrMinusOneIsInvalid
148 | {
149 | public SafeNativeHandle() : base(true) { }
150 | public SafeNativeHandle(IntPtr handle) : base(true) { this.handle = handle; }
151 |
152 | protected override bool ReleaseHandle()
153 | {
154 | return NativeMethods.CloseHandle(handle);
155 | }
156 | }
157 |
158 | internal enum SECURITY_IMPERSONATION_LEVEL
159 | {
160 | SecurityAnonymous = 0,
161 | SecurityIdentification = 1,
162 | SecurityImpersonation = 2,
163 | SecurityDelegation = 3,
164 | }
165 |
166 | internal enum SW
167 | {
168 | SW_HIDE = 0,
169 | SW_SHOWNORMAL = 1,
170 | SW_NORMAL = 1,
171 | SW_SHOWMINIMIZED = 2,
172 | SW_SHOWMAXIMIZED = 3,
173 | SW_MAXIMIZE = 3,
174 | SW_SHOWNOACTIVATE = 4,
175 | SW_SHOW = 5,
176 | SW_MINIMIZE = 6,
177 | SW_SHOWMINNOACTIVE = 7,
178 | SW_SHOWNA = 8,
179 | SW_RESTORE = 9,
180 | SW_SHOWDEFAULT = 10,
181 | SW_MAX = 10
182 | }
183 |
184 | internal enum TokenElevationType
185 | {
186 | TokenElevationTypeDefault = 1,
187 | TokenElevationTypeFull,
188 | TokenElevationTypeLimited,
189 | }
190 |
191 | internal enum TOKEN_TYPE
192 | {
193 | TokenPrimary = 1,
194 | TokenImpersonation = 2
195 | }
196 |
197 | internal enum WTS_CONNECTSTATE_CLASS
198 | {
199 | WTSActive,
200 | WTSConnected,
201 | WTSConnectQuery,
202 | WTSShadow,
203 | WTSDisconnected,
204 | WTSIdle,
205 | WTSListen,
206 | WTSReset,
207 | WTSDown,
208 | WTSInit
209 | }
210 |
211 | public class Win32Exception : System.ComponentModel.Win32Exception
212 | {
213 | private string _msg;
214 |
215 | public Win32Exception(string message) : this(Marshal.GetLastWin32Error(), message) { }
216 | public Win32Exception(int errorCode, string message) : base(errorCode)
217 | {
218 | _msg = String.Format("{0} ({1}, Win32ErrorCode {2} - 0x{2:X8})", message, base.Message, errorCode);
219 | }
220 |
221 | public override string Message { get { return _msg; } }
222 | public static explicit operator Win32Exception(string message) { return new Win32Exception(message); }
223 | }
224 |
225 | public static class ProcessExtensions
226 | {
227 | #region Win32 Constants
228 |
229 | private const int CREATE_UNICODE_ENVIRONMENT = 0x00000400;
230 | private const int CREATE_NO_WINDOW = 0x08000000;
231 |
232 | private const int CREATE_NEW_CONSOLE = 0x00000010;
233 |
234 | private const uint INVALID_SESSION_ID = 0xFFFFFFFF;
235 | private static readonly IntPtr WTS_CURRENT_SERVER_HANDLE = IntPtr.Zero;
236 |
237 | #endregion
238 |
239 | // Gets the user token from the currently active session
240 | private static SafeNativeHandle GetSessionUserToken()
241 | {
242 | var activeSessionId = INVALID_SESSION_ID;
243 | var pSessionInfo = IntPtr.Zero;
244 | var sessionCount = 0;
245 |
246 | // Get a handle to the user access token for the current active session.
247 | if (NativeMethods.WTSEnumerateSessions(WTS_CURRENT_SERVER_HANDLE, 0, 1, ref pSessionInfo, ref sessionCount))
248 | {
249 | try
250 | {
251 | var arrayElementSize = Marshal.SizeOf(typeof(NativeHelpers.WTS_SESSION_INFO));
252 | var current = pSessionInfo;
253 |
254 | for (var i = 0; i < sessionCount; i++)
255 | {
256 | var si = (NativeHelpers.WTS_SESSION_INFO)Marshal.PtrToStructure(
257 | current, typeof(NativeHelpers.WTS_SESSION_INFO));
258 | current = IntPtr.Add(current, arrayElementSize);
259 |
260 | if (si.State == WTS_CONNECTSTATE_CLASS.WTSActive)
261 | {
262 | activeSessionId = si.SessionID;
263 | break;
264 | }
265 | }
266 | }
267 | finally
268 | {
269 | NativeMethods.WTSFreeMemory(pSessionInfo);
270 | }
271 | }
272 |
273 | // If enumerating did not work, fall back to the old method
274 | if (activeSessionId == INVALID_SESSION_ID)
275 | {
276 | activeSessionId = NativeMethods.WTSGetActiveConsoleSessionId();
277 | }
278 |
279 | SafeNativeHandle hImpersonationToken;
280 | if (!NativeMethods.WTSQueryUserToken(activeSessionId, out hImpersonationToken))
281 | {
282 | throw new Win32Exception("WTSQueryUserToken failed to get access token.");
283 | }
284 |
285 | using (hImpersonationToken)
286 | {
287 | // First see if the token is the full token or not. If it is a limited token we need to get the
288 | // linked (full/elevated token) and use that for the CreateProcess task. If it is already the full or
289 | // default token then we already have the best token possible.
290 | TokenElevationType elevationType = GetTokenElevationType(hImpersonationToken);
291 |
292 | if (elevationType == TokenElevationType.TokenElevationTypeLimited)
293 | {
294 | using (var linkedToken = GetTokenLinkedToken(hImpersonationToken))
295 | return DuplicateTokenAsPrimary(linkedToken);
296 | }
297 | else
298 | {
299 | return DuplicateTokenAsPrimary(hImpersonationToken);
300 | }
301 | }
302 | }
303 |
304 | public static int StartProcessAsCurrentUser(string appPath, string cmdLine = null, string workDir = null, bool visible = true,int wait = -1)
305 | {
306 | using (var hUserToken = GetSessionUserToken())
307 | {
308 | var startInfo = new NativeHelpers.STARTUPINFO();
309 | startInfo.cb = Marshal.SizeOf(startInfo);
310 |
311 | uint dwCreationFlags = CREATE_UNICODE_ENVIRONMENT | (uint)(visible ? CREATE_NEW_CONSOLE : CREATE_NO_WINDOW);
312 | startInfo.wShowWindow = (short)(visible ? SW.SW_SHOW : SW.SW_HIDE);
313 | //startInfo.lpDesktop = "winsta0\\default";
314 |
315 | IntPtr pEnv = IntPtr.Zero;
316 | if (!NativeMethods.CreateEnvironmentBlock(ref pEnv, hUserToken, false))
317 | {
318 | throw new Win32Exception("CreateEnvironmentBlock failed.");
319 | }
320 | try
321 | {
322 | StringBuilder commandLine = new StringBuilder(cmdLine);
323 | var procInfo = new NativeHelpers.PROCESS_INFORMATION();
324 |
325 | if (!NativeMethods.CreateProcessAsUserW(hUserToken,
326 | appPath, // Application Name
327 | commandLine, // Command Line
328 | IntPtr.Zero,
329 | IntPtr.Zero,
330 | false,
331 | dwCreationFlags,
332 | pEnv,
333 | workDir, // Working directory
334 | ref startInfo,
335 | out procInfo))
336 | {
337 | throw new Win32Exception("CreateProcessAsUser failed.");
338 | }
339 |
340 | try
341 | {
342 | NativeMethods.WaitForSingleObject( procInfo.hProcess, wait);
343 | return procInfo.dwProcessId;
344 | }
345 | finally
346 | {
347 | NativeMethods.CloseHandle(procInfo.hThread);
348 | NativeMethods.CloseHandle(procInfo.hProcess);
349 | }
350 | }
351 | finally
352 | {
353 | NativeMethods.DestroyEnvironmentBlock(pEnv);
354 | }
355 | }
356 | }
357 |
358 | private static SafeNativeHandle DuplicateTokenAsPrimary(SafeHandle hToken)
359 | {
360 | SafeNativeHandle pDupToken;
361 | if (!NativeMethods.DuplicateTokenEx(hToken, 0, IntPtr.Zero, SECURITY_IMPERSONATION_LEVEL.SecurityImpersonation,
362 | TOKEN_TYPE.TokenPrimary, out pDupToken))
363 | {
364 | throw new Win32Exception("DuplicateTokenEx failed.");
365 | }
366 |
367 | return pDupToken;
368 | }
369 |
370 | private static TokenElevationType GetTokenElevationType(SafeHandle hToken)
371 | {
372 | using (SafeMemoryBuffer tokenInfo = GetTokenInformation(hToken, 18))
373 | {
374 | return (TokenElevationType)Marshal.ReadInt32(tokenInfo.DangerousGetHandle());
375 | }
376 | }
377 |
378 | private static SafeNativeHandle GetTokenLinkedToken(SafeHandle hToken)
379 | {
380 | using (SafeMemoryBuffer tokenInfo = GetTokenInformation(hToken, 19))
381 | {
382 | return new SafeNativeHandle(Marshal.ReadIntPtr(tokenInfo.DangerousGetHandle()));
383 | }
384 | }
385 |
386 | private static SafeMemoryBuffer GetTokenInformation(SafeHandle hToken, uint infoClass)
387 | {
388 | int returnLength;
389 | bool res = NativeMethods.GetTokenInformation(hToken, infoClass, new SafeMemoryBuffer(IntPtr.Zero), 0,
390 | out returnLength);
391 | int errCode = Marshal.GetLastWin32Error();
392 | if (!res && errCode != 24 && errCode != 122) // ERROR_INSUFFICIENT_BUFFER, ERROR_BAD_LENGTH
393 | {
394 | throw new Win32Exception(errCode, String.Format("GetTokenInformation({0}) failed to get buffer length", infoClass));
395 | }
396 |
397 | SafeMemoryBuffer tokenInfo = new SafeMemoryBuffer(returnLength);
398 | if (!NativeMethods.GetTokenInformation(hToken, infoClass, tokenInfo, returnLength, out returnLength))
399 | throw new Win32Exception(String.Format("GetTokenInformation({0}) failed", infoClass));
400 |
401 | return tokenInfo;
402 | }
403 | }
404 | }
405 | "@
406 | $Public = @(Get-ChildItem -Path $PSScriptRoot\Public\*.ps1 -ErrorAction SilentlyContinue)
407 | foreach ($import in @($Public))
408 | {
409 | try
410 | {
411 | . $import.FullName
412 | }
413 | catch
414 | {
415 | Write-Error -Message "Failed to import function $($import.FullName): $_"
416 | }
417 | }
--------------------------------------------------------------------------------
/Sources/ServiceUI.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/damienvanrobaeys/About_my_device/ada9466cff7abb0e991a90c30806291031326b17/Sources/ServiceUI.exe
--------------------------------------------------------------------------------
/Sources/assembly/LiveCharts.Wpf.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/damienvanrobaeys/About_my_device/ada9466cff7abb0e991a90c30806291031326b17/Sources/assembly/LiveCharts.Wpf.dll
--------------------------------------------------------------------------------
/Sources/assembly/LiveCharts.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/damienvanrobaeys/About_my_device/ada9466cff7abb0e991a90c30806291031326b17/Sources/assembly/LiveCharts.dll
--------------------------------------------------------------------------------
/Sources/assembly/LoadingIndicators.WPF.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/damienvanrobaeys/About_my_device/ada9466cff7abb0e991a90c30806291031326b17/Sources/assembly/LoadingIndicators.WPF.dll
--------------------------------------------------------------------------------
/Sources/assembly/MahApps.Metro.IconPacks.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/damienvanrobaeys/About_my_device/ada9466cff7abb0e991a90c30806291031326b17/Sources/assembly/MahApps.Metro.IconPacks.dll
--------------------------------------------------------------------------------
/Sources/assembly/MahApps.Metro.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/damienvanrobaeys/About_my_device/ada9466cff7abb0e991a90c30806291031326b17/Sources/assembly/MahApps.Metro.dll
--------------------------------------------------------------------------------
/Sources/assembly/System.Windows.Interactivity.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/damienvanrobaeys/About_my_device/ada9466cff7abb0e991a90c30806291031326b17/Sources/assembly/System.Windows.Interactivity.dll
--------------------------------------------------------------------------------
/Sources/depannage.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/damienvanrobaeys/About_my_device/ada9466cff7abb0e991a90c30806291031326b17/Sources/depannage.png
--------------------------------------------------------------------------------
/Sources/images/Thumbs.db:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/damienvanrobaeys/About_my_device/ada9466cff7abb0e991a90c30806291031326b17/Sources/images/Thumbs.db
--------------------------------------------------------------------------------
/Sources/images/about.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/damienvanrobaeys/About_my_device/ada9466cff7abb0e991a90c30806291031326b17/Sources/images/about.ico
--------------------------------------------------------------------------------
/Sources/images/hdd.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/damienvanrobaeys/About_my_device/ada9466cff7abb0e991a90c30806291031326b17/Sources/images/hdd.png
--------------------------------------------------------------------------------
/Sources/images/hdd1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/damienvanrobaeys/About_my_device/ada9466cff7abb0e991a90c30806291031326b17/Sources/images/hdd1.png
--------------------------------------------------------------------------------
/Sources/images/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/damienvanrobaeys/About_my_device/ada9466cff7abb0e991a90c30806291031326b17/Sources/images/logo.png
--------------------------------------------------------------------------------
/Sources/images/monitor.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/damienvanrobaeys/About_my_device/ada9466cff7abb0e991a90c30806291031326b17/Sources/images/monitor.png
--------------------------------------------------------------------------------
/Sources/images/support.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/damienvanrobaeys/About_my_device/ada9466cff7abb0e991a90c30806291031326b17/Sources/images/support.png
--------------------------------------------------------------------------------
/Sources/menu_pictures/exit.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/damienvanrobaeys/About_my_device/ada9466cff7abb0e991a90c30806291031326b17/Sources/menu_pictures/exit.png
--------------------------------------------------------------------------------
/Sources/menu_pictures/help.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/damienvanrobaeys/About_my_device/ada9466cff7abb0e991a90c30806291031326b17/Sources/menu_pictures/help.png
--------------------------------------------------------------------------------
/Sources/menu_pictures/help2.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/damienvanrobaeys/About_my_device/ada9466cff7abb0e991a90c30806291031326b17/Sources/menu_pictures/help2.ico
--------------------------------------------------------------------------------
/Sources/menu_pictures/log.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/damienvanrobaeys/About_my_device/ada9466cff7abb0e991a90c30806291031326b17/Sources/menu_pictures/log.png
--------------------------------------------------------------------------------
/Sources/menu_pictures/portal.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/damienvanrobaeys/About_my_device/ada9466cff7abb0e991a90c30806291031326b17/Sources/menu_pictures/portal.png
--------------------------------------------------------------------------------
/Sources/menu_pictures/quick_assist.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/damienvanrobaeys/About_my_device/ada9466cff7abb0e991a90c30806291031326b17/Sources/menu_pictures/quick_assist.png
--------------------------------------------------------------------------------
/Sources/menu_pictures/sync2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/damienvanrobaeys/About_my_device/ada9466cff7abb0e991a90c30806291031326b17/Sources/menu_pictures/sync2.png
--------------------------------------------------------------------------------
/Sources/nssm.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/damienvanrobaeys/About_my_device/ada9466cff7abb0e991a90c30806291031326b17/Sources/nssm.exe
--------------------------------------------------------------------------------
/Sources/resources/custom.xaml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
43 |
44 |
--------------------------------------------------------------------------------
/Sources/runasuser.psm1:
--------------------------------------------------------------------------------
1 | $script:source = @"
2 | using Microsoft.Win32.SafeHandles;
3 | using System;
4 | using System.Runtime.InteropServices;
5 | using System.Text;
6 |
7 | namespace RunAsUser
8 | {
9 | internal class NativeHelpers
10 | {
11 | [StructLayout(LayoutKind.Sequential)]
12 | public struct PROCESS_INFORMATION
13 | {
14 | public IntPtr hProcess;
15 | public IntPtr hThread;
16 | public int dwProcessId;
17 | public int dwThreadId;
18 | }
19 |
20 | [StructLayout(LayoutKind.Sequential)]
21 | public struct STARTUPINFO
22 | {
23 | public int cb;
24 | public String lpReserved;
25 | public String lpDesktop;
26 | public String lpTitle;
27 | public uint dwX;
28 | public uint dwY;
29 | public uint dwXSize;
30 | public uint dwYSize;
31 | public uint dwXCountChars;
32 | public uint dwYCountChars;
33 | public uint dwFillAttribute;
34 | public uint dwFlags;
35 | public short wShowWindow;
36 | public short cbReserved2;
37 | public IntPtr lpReserved2;
38 | public IntPtr hStdInput;
39 | public IntPtr hStdOutput;
40 | public IntPtr hStdError;
41 | }
42 |
43 | [StructLayout(LayoutKind.Sequential)]
44 | public struct WTS_SESSION_INFO
45 | {
46 | public readonly UInt32 SessionID;
47 |
48 | [MarshalAs(UnmanagedType.LPStr)]
49 | public readonly String pWinStationName;
50 |
51 | public readonly WTS_CONNECTSTATE_CLASS State;
52 | }
53 | }
54 |
55 | internal class NativeMethods
56 | {
57 | [DllImport("kernel32", SetLastError=true)]
58 | public static extern int WaitForSingleObject(
59 | IntPtr hHandle,
60 | int dwMilliseconds);
61 |
62 | [DllImport("kernel32.dll", SetLastError = true)]
63 | public static extern bool CloseHandle(
64 | IntPtr hSnapshot);
65 |
66 | [DllImport("userenv.dll", SetLastError = true)]
67 | public static extern bool CreateEnvironmentBlock(
68 | ref IntPtr lpEnvironment,
69 | SafeHandle hToken,
70 | bool bInherit);
71 |
72 | [DllImport("advapi32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
73 | public static extern bool CreateProcessAsUserW(
74 | SafeHandle hToken,
75 | String lpApplicationName,
76 | StringBuilder lpCommandLine,
77 | IntPtr lpProcessAttributes,
78 | IntPtr lpThreadAttributes,
79 | bool bInheritHandle,
80 | uint dwCreationFlags,
81 | IntPtr lpEnvironment,
82 | String lpCurrentDirectory,
83 | ref NativeHelpers.STARTUPINFO lpStartupInfo,
84 | out NativeHelpers.PROCESS_INFORMATION lpProcessInformation);
85 |
86 | [DllImport("userenv.dll", SetLastError = true)]
87 | [return: MarshalAs(UnmanagedType.Bool)]
88 | public static extern bool DestroyEnvironmentBlock(
89 | IntPtr lpEnvironment);
90 |
91 | [DllImport("advapi32.dll", SetLastError = true)]
92 | public static extern bool DuplicateTokenEx(
93 | SafeHandle ExistingTokenHandle,
94 | uint dwDesiredAccess,
95 | IntPtr lpThreadAttributes,
96 | SECURITY_IMPERSONATION_LEVEL ImpersonationLevel,
97 | TOKEN_TYPE TokenType,
98 | out SafeNativeHandle DuplicateTokenHandle);
99 |
100 | [DllImport("advapi32.dll", SetLastError = true)]
101 | public static extern bool GetTokenInformation(
102 | SafeHandle TokenHandle,
103 | uint TokenInformationClass,
104 | SafeMemoryBuffer TokenInformation,
105 | int TokenInformationLength,
106 | out int ReturnLength);
107 |
108 | [DllImport("wtsapi32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
109 | public static extern bool WTSEnumerateSessions(
110 | IntPtr hServer,
111 | int Reserved,
112 | int Version,
113 | ref IntPtr ppSessionInfo,
114 | ref int pCount);
115 |
116 | [DllImport("wtsapi32.dll")]
117 | public static extern void WTSFreeMemory(
118 | IntPtr pMemory);
119 |
120 | [DllImport("kernel32.dll")]
121 | public static extern uint WTSGetActiveConsoleSessionId();
122 |
123 | [DllImport("Wtsapi32.dll", SetLastError = true)]
124 | public static extern bool WTSQueryUserToken(
125 | uint SessionId,
126 | out SafeNativeHandle phToken);
127 | }
128 |
129 | internal class SafeMemoryBuffer : SafeHandleZeroOrMinusOneIsInvalid
130 | {
131 | public SafeMemoryBuffer(int cb) : base(true)
132 | {
133 | base.SetHandle(Marshal.AllocHGlobal(cb));
134 | }
135 | public SafeMemoryBuffer(IntPtr handle) : base(true)
136 | {
137 | base.SetHandle(handle);
138 | }
139 |
140 | protected override bool ReleaseHandle()
141 | {
142 | Marshal.FreeHGlobal(handle);
143 | return true;
144 | }
145 | }
146 |
147 | internal class SafeNativeHandle : SafeHandleZeroOrMinusOneIsInvalid
148 | {
149 | public SafeNativeHandle() : base(true) { }
150 | public SafeNativeHandle(IntPtr handle) : base(true) { this.handle = handle; }
151 |
152 | protected override bool ReleaseHandle()
153 | {
154 | return NativeMethods.CloseHandle(handle);
155 | }
156 | }
157 |
158 | internal enum SECURITY_IMPERSONATION_LEVEL
159 | {
160 | SecurityAnonymous = 0,
161 | SecurityIdentification = 1,
162 | SecurityImpersonation = 2,
163 | SecurityDelegation = 3,
164 | }
165 |
166 | internal enum SW
167 | {
168 | SW_HIDE = 0,
169 | SW_SHOWNORMAL = 1,
170 | SW_NORMAL = 1,
171 | SW_SHOWMINIMIZED = 2,
172 | SW_SHOWMAXIMIZED = 3,
173 | SW_MAXIMIZE = 3,
174 | SW_SHOWNOACTIVATE = 4,
175 | SW_SHOW = 5,
176 | SW_MINIMIZE = 6,
177 | SW_SHOWMINNOACTIVE = 7,
178 | SW_SHOWNA = 8,
179 | SW_RESTORE = 9,
180 | SW_SHOWDEFAULT = 10,
181 | SW_MAX = 10
182 | }
183 |
184 | internal enum TokenElevationType
185 | {
186 | TokenElevationTypeDefault = 1,
187 | TokenElevationTypeFull,
188 | TokenElevationTypeLimited,
189 | }
190 |
191 | internal enum TOKEN_TYPE
192 | {
193 | TokenPrimary = 1,
194 | TokenImpersonation = 2
195 | }
196 |
197 | internal enum WTS_CONNECTSTATE_CLASS
198 | {
199 | WTSActive,
200 | WTSConnected,
201 | WTSConnectQuery,
202 | WTSShadow,
203 | WTSDisconnected,
204 | WTSIdle,
205 | WTSListen,
206 | WTSReset,
207 | WTSDown,
208 | WTSInit
209 | }
210 |
211 | public class Win32Exception : System.ComponentModel.Win32Exception
212 | {
213 | private string _msg;
214 |
215 | public Win32Exception(string message) : this(Marshal.GetLastWin32Error(), message) { }
216 | public Win32Exception(int errorCode, string message) : base(errorCode)
217 | {
218 | _msg = String.Format("{0} ({1}, Win32ErrorCode {2} - 0x{2:X8})", message, base.Message, errorCode);
219 | }
220 |
221 | public override string Message { get { return _msg; } }
222 | public static explicit operator Win32Exception(string message) { return new Win32Exception(message); }
223 | }
224 |
225 | public static class ProcessExtensions
226 | {
227 | #region Win32 Constants
228 |
229 | private const int CREATE_UNICODE_ENVIRONMENT = 0x00000400;
230 | private const int CREATE_NO_WINDOW = 0x08000000;
231 |
232 | private const int CREATE_NEW_CONSOLE = 0x00000010;
233 |
234 | private const uint INVALID_SESSION_ID = 0xFFFFFFFF;
235 | private static readonly IntPtr WTS_CURRENT_SERVER_HANDLE = IntPtr.Zero;
236 |
237 | #endregion
238 |
239 | // Gets the user token from the currently active session
240 | private static SafeNativeHandle GetSessionUserToken()
241 | {
242 | var activeSessionId = INVALID_SESSION_ID;
243 | var pSessionInfo = IntPtr.Zero;
244 | var sessionCount = 0;
245 |
246 | // Get a handle to the user access token for the current active session.
247 | if (NativeMethods.WTSEnumerateSessions(WTS_CURRENT_SERVER_HANDLE, 0, 1, ref pSessionInfo, ref sessionCount))
248 | {
249 | try
250 | {
251 | var arrayElementSize = Marshal.SizeOf(typeof(NativeHelpers.WTS_SESSION_INFO));
252 | var current = pSessionInfo;
253 |
254 | for (var i = 0; i < sessionCount; i++)
255 | {
256 | var si = (NativeHelpers.WTS_SESSION_INFO)Marshal.PtrToStructure(
257 | current, typeof(NativeHelpers.WTS_SESSION_INFO));
258 | current = IntPtr.Add(current, arrayElementSize);
259 |
260 | if (si.State == WTS_CONNECTSTATE_CLASS.WTSActive)
261 | {
262 | activeSessionId = si.SessionID;
263 | break;
264 | }
265 | }
266 | }
267 | finally
268 | {
269 | NativeMethods.WTSFreeMemory(pSessionInfo);
270 | }
271 | }
272 |
273 | // If enumerating did not work, fall back to the old method
274 | if (activeSessionId == INVALID_SESSION_ID)
275 | {
276 | activeSessionId = NativeMethods.WTSGetActiveConsoleSessionId();
277 | }
278 |
279 | SafeNativeHandle hImpersonationToken;
280 | if (!NativeMethods.WTSQueryUserToken(activeSessionId, out hImpersonationToken))
281 | {
282 | throw new Win32Exception("WTSQueryUserToken failed to get access token.");
283 | }
284 |
285 | using (hImpersonationToken)
286 | {
287 | // First see if the token is the full token or not. If it is a limited token we need to get the
288 | // linked (full/elevated token) and use that for the CreateProcess task. If it is already the full or
289 | // default token then we already have the best token possible.
290 | TokenElevationType elevationType = GetTokenElevationType(hImpersonationToken);
291 |
292 | if (elevationType == TokenElevationType.TokenElevationTypeLimited)
293 | {
294 | using (var linkedToken = GetTokenLinkedToken(hImpersonationToken))
295 | return DuplicateTokenAsPrimary(linkedToken);
296 | }
297 | else
298 | {
299 | return DuplicateTokenAsPrimary(hImpersonationToken);
300 | }
301 | }
302 | }
303 |
304 | public static int StartProcessAsCurrentUser(string appPath, string cmdLine = null, string workDir = null, bool visible = true,int wait = -1)
305 | {
306 | using (var hUserToken = GetSessionUserToken())
307 | {
308 | var startInfo = new NativeHelpers.STARTUPINFO();
309 | startInfo.cb = Marshal.SizeOf(startInfo);
310 |
311 | uint dwCreationFlags = CREATE_UNICODE_ENVIRONMENT | (uint)(visible ? CREATE_NEW_CONSOLE : CREATE_NO_WINDOW);
312 | startInfo.wShowWindow = (short)(visible ? SW.SW_SHOW : SW.SW_HIDE);
313 | //startInfo.lpDesktop = "winsta0\\default";
314 |
315 | IntPtr pEnv = IntPtr.Zero;
316 | if (!NativeMethods.CreateEnvironmentBlock(ref pEnv, hUserToken, false))
317 | {
318 | throw new Win32Exception("CreateEnvironmentBlock failed.");
319 | }
320 | try
321 | {
322 | StringBuilder commandLine = new StringBuilder(cmdLine);
323 | var procInfo = new NativeHelpers.PROCESS_INFORMATION();
324 |
325 | if (!NativeMethods.CreateProcessAsUserW(hUserToken,
326 | appPath, // Application Name
327 | commandLine, // Command Line
328 | IntPtr.Zero,
329 | IntPtr.Zero,
330 | false,
331 | dwCreationFlags,
332 | pEnv,
333 | workDir, // Working directory
334 | ref startInfo,
335 | out procInfo))
336 | {
337 | throw new Win32Exception("CreateProcessAsUser failed.");
338 | }
339 |
340 | try
341 | {
342 | NativeMethods.WaitForSingleObject( procInfo.hProcess, wait);
343 | return procInfo.dwProcessId;
344 | }
345 | finally
346 | {
347 | NativeMethods.CloseHandle(procInfo.hThread);
348 | NativeMethods.CloseHandle(procInfo.hProcess);
349 | }
350 | }
351 | finally
352 | {
353 | NativeMethods.DestroyEnvironmentBlock(pEnv);
354 | }
355 | }
356 | }
357 |
358 | private static SafeNativeHandle DuplicateTokenAsPrimary(SafeHandle hToken)
359 | {
360 | SafeNativeHandle pDupToken;
361 | if (!NativeMethods.DuplicateTokenEx(hToken, 0, IntPtr.Zero, SECURITY_IMPERSONATION_LEVEL.SecurityImpersonation,
362 | TOKEN_TYPE.TokenPrimary, out pDupToken))
363 | {
364 | throw new Win32Exception("DuplicateTokenEx failed.");
365 | }
366 |
367 | return pDupToken;
368 | }
369 |
370 | private static TokenElevationType GetTokenElevationType(SafeHandle hToken)
371 | {
372 | using (SafeMemoryBuffer tokenInfo = GetTokenInformation(hToken, 18))
373 | {
374 | return (TokenElevationType)Marshal.ReadInt32(tokenInfo.DangerousGetHandle());
375 | }
376 | }
377 |
378 | private static SafeNativeHandle GetTokenLinkedToken(SafeHandle hToken)
379 | {
380 | using (SafeMemoryBuffer tokenInfo = GetTokenInformation(hToken, 19))
381 | {
382 | return new SafeNativeHandle(Marshal.ReadIntPtr(tokenInfo.DangerousGetHandle()));
383 | }
384 | }
385 |
386 | private static SafeMemoryBuffer GetTokenInformation(SafeHandle hToken, uint infoClass)
387 | {
388 | int returnLength;
389 | bool res = NativeMethods.GetTokenInformation(hToken, infoClass, new SafeMemoryBuffer(IntPtr.Zero), 0,
390 | out returnLength);
391 | int errCode = Marshal.GetLastWin32Error();
392 | if (!res && errCode != 24 && errCode != 122) // ERROR_INSUFFICIENT_BUFFER, ERROR_BAD_LENGTH
393 | {
394 | throw new Win32Exception(errCode, String.Format("GetTokenInformation({0}) failed to get buffer length", infoClass));
395 | }
396 |
397 | SafeMemoryBuffer tokenInfo = new SafeMemoryBuffer(returnLength);
398 | if (!NativeMethods.GetTokenInformation(hToken, infoClass, tokenInfo, returnLength, out returnLength))
399 | throw new Win32Exception(String.Format("GetTokenInformation({0}) failed", infoClass));
400 |
401 | return tokenInfo;
402 | }
403 | }
404 | }
405 | "@
406 | $Public = @(Get-ChildItem -Path $PSScriptRoot\Public\*.ps1 -ErrorAction SilentlyContinue)
407 | foreach ($import in @($Public))
408 | {
409 | try
410 | {
411 | . $import.FullName
412 | }
413 | catch
414 | {
415 | Write-Error -Message "Failed to import function $($import.FullName): $_"
416 | }
417 | }
--------------------------------------------------------------------------------
/preview.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/damienvanrobaeys/About_my_device/ada9466cff7abb0e991a90c30806291031326b17/preview.gif
--------------------------------------------------------------------------------