SYSTEMINDEX returns paths those do not exist - windows

Environment
I have windows 10 with two languages installed
first one is Polish(i use it as main language in the system) second one is English.
I'm able to open directories in the explorer using english and polish paths ie.
C:\Users\User\Desktop and C:\Użytkownicy\User\Pulpit
Code
I'm trying to figure out if it is problem with SYSTEMINDEX or windows at all.
i have folllwing query to the SYSTEMINDEX
$sql = "SELECT System.ItemFolderPathDisplay FROM SYSTEMINDEX WHERE System.fileExtension
later when i terate through query i do the following
Get-Item $rs.Fields.Item("System.ItemFolderPathDisplay").Value).fullname
But paths stored in the SYSTEMINDEX are localized ones like C:\Użytkownicy\User\Pulpit\file.txt
and Get-Item returns an error
powershell search: Get-Item : Cannot find path 'C:\Użytkownicy\User\Pulpit\file.txt' because it does not exist.
So i wonder if there is some flag which i can set so Paths will be returned in the non-localized form? Or maybe it is some kind of bug in windows?

Related

Exception calling fill with 1 argument ora-00933 sql command not properly ended

I'm having the above error message when I use powershell 5.1 in vscode to execute an oracle sql query. I'm testing with a simple sql statement, but eventually it will be more complicated and the more complicated sql has at least 3 semicolons.
I'm looking at remove semicolons which said to remove semicolons, but I know this won't ultimately fix it because of my query. I'm unclear what their other numbered solutions are saying to do.
I know sqlPlus isn't working for me for this because of a possible oracle driver issue. Right now I'm trying the following:
Add-Type -AssemblyName System.Data.OracleClient #at the top
...
$dataSource = "RMMPRDBLAH.company.net:1521/RMMPRDB"
$connectionString = "Data Source=$dataSource;User Id=$username;Password=$password;"
$con = New-Object System.Data.OracleClient.OracleConnection($connectionString)
$query = "select * from SEVERITY_TBL;" #Get-Content $sqlPath
Write-Host "query: $query"
$con.open()
$dtSet = New-Object System.Data.DataSet
$OracleAdapter = New-Object System.Data.OracleClient.OracleDataAdapter($query,$con)
[void]$OracleAdapter.Fill($dtSet)
Which works fine until .Fill, where I get the error message. When I remove the semicolon from my simple query, it returns results, but like I said, ultimately I have a 200 line query to read from a file which has multiple semicolons, so I need to be able to have the semicolons. I was having trouble trying to use ManagedDataAccess.Client.OracleDataAdapter (maybe I need to do something other than Add-Type -AssemblyName System.Data.OracleClient) for this, so I'm using OracleClient.OracleDataAdapter, which was fine until I found the semicolon issue. How can I get this to work with the semicolon without sqlplus? I have the Oracle Developer Tools for VS Code.
When I tried this method (which I'm not sure if this would help my semicolon issue)
$cmd = New-Object Oracle.ManagedDataAccess.Client.OracleCommand
It had this error, which I'm not sure how to fix:
New-Object : Cannot find type
[Oracle.ManagedDataAccess.Client.OracleCommand]: verify that the
assembly containing this type is loaded.
Thanks!
Update:
I was able to simplify my long query so that it doesn't have more than one semicolon. I see the issue with having multiples. After I made this change, it Got past the fill.
In .net if we are trying to try parsing wrong type it can be issue.
ex:-if we trying to do int.TryParse for long/Guid type values

Reading REG_QWORD with VBScript?

I think the question speaks for itself. I have trouble getting some values out of the registry, and I was hoping someone around here might help me.
I'm stuck at IE9, as it is the only one which has some reasonable CSS capabilities, and does support GetObject().
So right now, lets say I'm trying to retrieve the memory size of a GPU at "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Class\{4d36e968-e325-11ce-bfc1-08002be10318}\0000\HardwareInformation.qwMemorySize" (as far as I know, this should be a universal path & key).
This is where the problem begins. Either I get no output, or some error saying something is different, or what (my system is running in a different language so I cant offer the right translation).
After some research, I seem to have found the issue - the value I'm trying to read is REG_QWORD, and unfortunately I was only able to find very little covering this topic, and most of the solutions did not work for me.
So right now, I am with this code, which, unsurprisingly, also does not work (the code I had since like the beginning):
for Each oItem in colGPUs
memory = oItem.AdapterRAM / 1048576
If memory < 0 Then
If InStr(oItem.Name, "NVIDIA") Then
Set wssx = CreateObject("WScript.Shell")
msgbox CStr(wssx.RegRead("HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Class\{4d36e968-e325-11ce-bfc1-08002be10318}\000" + GPUID + "\HardwareInformation.qwMemorySize"))
End If
End If
Unfortunatelly it seems like there is no direct way of retrieving the value - within HTA itself.
I was able to get the value, however I did it using Powershell, executed the command, set its output to a specific file and read it.
Anyways, here is the actual solution I came up with specifically for this issue
wshell.Run "powershell (Get-ItemPropertyValue 'HKLM:\SYSTEM\ControlSet001\Control\Class\{4d36e968-e325-11ce-bfc1-08002be10318}\0000' 'HardwareInformation.qwMemorySize') | Out-File -FilePath C:\temp\gpu_mem.txt", 0, true
Set f = fso.OpenTextFile("C:\temp\gpu_mem.txt", 1, False, -1)
gpu_mem = CStr(f.ReadAll)
With this method Im directly obtaining the integer and passing it to the VBS

Change Chrome Settings via Powershell

I want to make a script to change the default page zoom in Chrome, however I do not know where these options are stored.
I guess that I have to find an appropriate options text file, parse it, and then make a textual replacement there, using powershell in order to apply the changes.
I need to do it every time I plugin my laptop to an external monitor, and it is kinda annowying to do it by hand
Any ideas?
The default zoom level is stored in a huge JSON config file called Preferences, that can be found in the local appdata folder:
$LocalAppData = [Environment]::GetFolderPath( [Environment+SpecialFolder]::LocalApplicationData )
$ChromeDefaults = Join-Path $LocalAppData "Google\Chrome\User Data\default"
$ChromePrefFile = Join-Path $ChromeDefaults "Preferences"
$Settings = Get-Content $ChromePrefFile | ConvertFrom-Json
The default Page Zoom level is stored under the partition object, although it seems to store it as a unique identifier with some sort of ratio value, this is what it looks like with 100% zoom:
PS C:\> $Settings.partition.default_zoom_level | Format-List
2166136261 : 0.0
Other than that, I have no idea. I don't expect this to be a good idea, Chrome seems to update a number of binary values everytime the default files are updated, you might end up with a corrupt Preferences file
$Env:
Is a special PSdrive that contains many of the SpecialFolder Paths
$Env:LOCALAPPDATA
and
[Environment]::GetFolderPath( [Environment+SpecialFolder]::LocalApplicationData )
Yield the same result in addition to the rest of Mathias answer.

Powershell - filtering output of command

I'm quite new to powershell, but I've done a lot of batch scripting (yay for moving into the 'now!'). I'm trying to re-write my largest accomplishment in batch scripting into powershell, and right off the bat I'm hitting a bit of a wall.
What my original batch script did was install drivers for all of the detected system hardware. It did this by running devcon.exe and doing a search on the output, looking for VEN_ &DEV_ and trying to match it up with a comparison. This took a bit of time on slower computers (i3/Atom/slow AMD).
I stumbled across this command in powershell:
get-wmiobject -class CIM_VideoController PNPDeviceID
It spits out a list which contains just a few bits of info on the display adapter. The line in particular I'd like is the PNPDeviceID. I so far haven't had much luck in finding a way to manupulate the output to list just the VEN_ numbers.
Here's what I'd like to do: Run the command above, manipulate it so I get just the vendor number into one variable and the device number into another variable.
I tried doing this:
get-wmiobject -class CIM_VideoController PNPDeviceID | Select-String -Pattern "PNPDeviceID" -SimpleMatch
The problem I'm having is, it spits out nothing at all. I also have no clue on how to manipulate the output of that line further giving me only the 4 digit identifier of the 'VEN_' or the 'DEV_'.
Would anyone know how to do this?
I mean no disrespect, but this is pretty basic stuff. Have you considered finding a book (even an online one) and reading up on PowerShell? I've heard good things about Learning PowerShell In A Month Of Lunches.
As for your request, to get the four digit ID you could pipe that property's value to a regex match, and then output that match. It could be done like this:
$VidCardID = get-wmiobject -class CIM_VideoController PNPDeviceID | Where{$_.PNPDeviceID -match "VEN_(\d{4})"} | ForEach{$Matches[1]}
That will set $VidCardID to the 4 digit ID for the video card.
You can just do this:
$deviceID = (get-wmiobject -class CIM_VideoController).PNPDeviceID
the output of such objects are allways stored in a property which you can access by dot notation

Search filesystem for filepath using VBA

I am looking for a way to search a specific folder for a subfolder containing a certain string. Below I have listed a function I typed off the top of my head to see if it would work. Well, it does work but when I am talking about searching through 6,000 folders on a network drive it just isn't fast enough.
I'm sure that there is a better way to do it but I can't seem to dig anything up on Google.
Is there an object that allows me to leverage the windows built in file system searching and indexing capabilities?
As an alternative, does someone have a way to optimize my code? The main bottleneck is the usage of instr.
Here is the code:
Function findPath(strId As String) As String
checkObj
Dim strBase As String
strBase = opt.photoBasePath
Dim fs As Object
Set fs = CreateObject("Scripting.FileSystemObject")
Dim baseFolder As Object
Set baseFolder = fs.getfolder(strBase)
Dim folder As Object
For Each folder In baseFolder.subfolders
If InStr(1, folder.name, strId) > 0 Then
findPath = strBase & "\" & folder.name
Exit Function
End If
Next folder
End Function
P.S. I'm sure someone will suggest modifying my folder structure so that I can programmatically predict the path but for various reason that isn't possible in my case.
You could use the FindFirstFile Win32 API, which allows you to search for files or sudirectories matching a specified name. Additionally, you could also use the FindFirstFileEx function, along with a FINDEX_SEARCH_OPS parameter of FindExSearchLimitToDirectories, which would limit your search to a file that matches a specified name and is also a directory (if the file system supports directory filtering). For more information on using these functions from VB/VBA see the following:
http://www.xtremevbtalk.com/showpost.php?p=1157418&postcount=4
http://support.microsoft.com/kb/185476
http://www.ask-4it.com/how-to-use-findfirstfile-win32-api-from-visual-basic-code-2-ca.html
Consider splitting traversing the folders from finding your key. Instead of the instr test, store the folder names in a table, then use a query on the table to find your target. It might be slower, but searching should be faster.

Resources