Protect what matters – even after you're gone. Make a plan for your digital legacy today.
Forum Discussion
oxgl
2 years agoNew Contributor
Dynamic fields in URL
Hello!
First of all, thank you for this product — it’s almost perfect for me. I’m currently using KeePassXC while testing the trial version of 1Password.
The Linux version works perfectly, but ...
oxgl
3 months agoNew Contributor
Hi everyone,
Sorry for not getting back sooner! I know some of you asked me to upload the solution, but I didn’t receive or maybe just didn’t notice any follow-up information about it. Didn’t mean to leave you hanging — thanks a lot for your patience!
Here is my solution:
Create a file sapgui_ph.ps1, and paste the following script into it - this will be the protocol handler for scheme "sapgui:":
param(
[string]$sapguiUrl
)
Add-Type -AssemblyName System.Web
# Function to parse the URL parameters
function Parse-SapGuiUrl {
param (
[string]$url
)
# Remove the sapgui:// part from the URL
$url = $url -replace '^sapgui://', ''
$url = $url -replace '^sapgui:', ''
# Split the URL into components (assuming the URL format is something like sapgui://system=<system>&user=<user>&pw=<password>)
$params = @{}
$url.Split('&') | ForEach-Object {
$key, $value = $_.Split('=')
if ($key -and $value) {
$params[[System.Web.HttpUtility]::UrlDecode($key)] = [System.Web.HttpUtility]::UrlDecode($value)
}
}
return $params
}
# Parse the URL parameters
$params = Parse-SapGuiUrl -url $sapguiUrl
# Output the parameters for verification (you can remove this line later)
#Write-Host "Parsed Parameters: $($params | Out-String)"
# Check if necessary parameters are present (like system, user, etc.)
if ($params['system'] -and $params['client'] -and $params['user'] -and $params['pw']) {
$system = $params['system']
$client = $params['client']
$user = $params['user']
$pw = $params['pw']
$lang = $params['lang']
if (-not $lang) {
$lang = 'E'
}
# Example command execution (this could be a call to the SAP GUI or another command)
Write-Host "Connecting to SAP System: $system, client: $client, with user: $user"
# You can now execute your SAP GUI command or other related actions here
# For example, launch an SAP GUI connection with the parameters (this is just an example)
# Start-Process "sapgui.exe" -ArgumentList "/system:$system /user:$user /client:$client"
Start-Process -FilePath "C:\Program Files\SAP\FrontEnd\SAPGUI\sapshcut.exe" -ArgumentList "-system=`"$system`"", "-client=`"$client`"", "-user=`"$username`"", "-pw=`"$pw`"", "-language=$lang", "-maxgui"
#Read-Host "Press enter..."
} else {
Write-Host "Missing required parameters in the URL."
}
Create a second file sapgui_ph_register.ps1 in the same directory, this will contain the script which will register the first file as a protocol handler for scheme "sapgui:":
$protocolName = "sapgui"
# Get the full path by combining the script directory with the filename
$scriptPath = Join-Path -Path $PSScriptRoot -ChildPath "sapgui_ph.ps1"
# Escape backslashes in the path (for registry compatibility)
$escapedScriptPath = $scriptPath -replace '\\', '\\\\'
# Define the registry key paths
$protocolKey = "HKCU:\Software\Classes\$protocolName"
$commandKey = "HKCU:\Software\Classes\$protocolName\shell\open\command"
# Create the registry entries
New-Item -Path $protocolKey -Force | Out-Null
Set-ItemProperty -Path $protocolKey -Name "(Default)" -Value "URL:$protocolName Protocol"
Set-ItemProperty -Path $protocolKey -Name "URL Protocol" -Value ""
# Set the command to run PowerShell with the script, passing the URL as an argument
New-Item -Path $commandKey -Force | Out-Null
Set-ItemProperty -Path $commandKey -Name "(Default)" -Value "`"powershell.exe`" -ExecutionPolicy Bypass -File `"$escapedScriptPath`" `"%1`""
Write-Host "Protocol handler for '$protocolName' registered successfully."
Now just run the script sapgui_ph_register.ps1
In 1Password add a website field:
Unfortunately, 1Password does not allow us to reference field values (at least that was the case a few months ago), so we have to construct this URI manually. Here’s how:
- Put the SAP System ID after system=...
- Put the Client after client=...
- Put the Username after user=...
- Put your Password after pw=...
- Don’t forget the ampersand (&) at the end
All values must be URL-encoded before inserting them into the URI. You can use a tool like https://www.urlencoder.org/ to encode your values.
Example:
- System ID: CRM
- Client: 100
- User ID: oxgl
- Password: pass&word! (URL-encoded as pass%26word%21)
The resulting URI will be:
sapgui:system=CRM&client=100&user=oxgl&pw=pass%26word%21&By default, this will log in using English. For non-English logins, you can add the &lang=X parameter, where X is the short language code (for example, C for Czech).
This works with 1Password Quick Access (Ctrl + Shift + Space).
Hope this helps!
oxgl