1

I'm a relatively new Developer building my first app.

Right now I'm in the process of developing a UWP app and I am needing to get the Hard Drive Serial number from the PC from the Views (OnNavigatedTo), then after a few more fields are filled out, to then save all values to a SQL Server.

What I have discovered up to this point:

  • Grabbing some values like Hard Drive SN are not so easy with UWP.
  • I don't seem to have access to Registry HKLM via UWP
  • I can grab it very easily with PowerShell, and write it to a JSON or XML file. which I plan to do with a Service Account when PC is imaged.
  • I Don't know where to put the file where the App can see it.
  • Writing to Sql Server can only be done by creating a webservice and making HTTP / JSON calls via App. (I have this part setup but have not started accessing it via app yet)

So the part I really need help with I guess, is Where to Put JSON/XML file that App will be able to see and read from. Unless of course, someone knows of another way to get Hard Drive SN into a UWP app.

Thanks for Any Help

TheGameiswar
  • 27,855
  • 8
  • 56
  • 94
ekgcorp
  • 165
  • 1
  • 11
  • If you're going to have a powershell script, why wouldn't it write it to the database? – James Z Mar 24 '17 at 14:36
  • I don't think I know Powershell Script well enough for that... do you have an idea of what that code would look like, and what permission/account would the script need to be run as to make that happen? – ekgcorp Mar 24 '17 at 14:39
  • You can see for example this question: http://stackoverflow.com/questions/8423541/how-do-you-run-a-sql-server-query-from-powershell – James Z Mar 24 '17 at 14:40
  • Would it not be advisable / possible to read from a local file on the PC created by a PS? After all, if the most efficient why to do this is for the PowerShell to write directly to the DB then so be it. However, after following the link you provided, it appears that some mentioned a problem with leaving a script on a PC that could leave it prone to SQL Injection attacks.. Plus, down the road I would like for the user to be able to rerun the process again if a new HardDrive is put in the pc. – ekgcorp Mar 24 '17 at 16:37

1 Answers1

1

The recommended way to do this (if you want to go to the Windows Store) is to use a FileOpenPicker and have the user choose the file manually.

If this is for side-loading only (not going to the Windows Store) you can write the file to the user's Documents folder and then the UWP can read it using documentsLibrary capability without any user intervention. You could also use a fullTrust extension to run the PowerShell script and to put the file in the app's data folder. You can check out the Desktop Bridge docs for more info on fullTrust extensions.

Peter Torr - MSFT
  • 11,824
  • 3
  • 18
  • 51
  • I'm 99% sure this will be Side Loaded.. Do you think you could expound on the fullTrust extension, and is that something (the PS Script) that can be ran again down the road to update the file I'm storing data too? – ekgcorp Mar 25 '17 at 16:38