Powershell Loaded Assemblies ’Wtsapi32′ - powershell

I have a requirement to write a script that will launch a new process, as an existing/logged in user, into there specific session, with powershell.
Ive done some research and it seems as though I can use the ’Wtsapi32′ module to get the user session token, duplicate it and launch the process as that user. However, Im not sure how to call the loaded module. Does anyone have an tips/hints on this? ie for ‘WTSQueryUserToken’?
An example of what my logic and research is here My link

Related

Creating a custom powershell module without exposing code

I want to create a custom powershell module that I can distribute without exposing the code. The script includes API calls with app specific private keys that I don't want to compromise. I've seen a lot of discussions about this over the years, but nothing that really solves my problem.
Is there a good way to create a custom powershell module without exposing the underlying code? I want to be able to distribute the powershell module, for others to import or install.
this may be what you are looking for : https://www.powershellgallery.com/packages/ps2exe/1.0.11
but be careful, the API key will still be in the compiled file at someplace. You can try and cipher it, but if it's needed for your script, it will be in your file no matter how you try to hide it. the question is why do you need to ship it inside your script in the first place ? I mean that any of your script's user will be using your private key which is likely not what you want to do

Pass arguments to application hosted by Appv but run up via Citrix

ok I'm no expert in this so I might explain wrong. We are trying to find a way to pass parameters to an app in appV but is launched by Citrix SelfService. So I guess when you have apps in appv you tell it you want to call an app by calling ctxAppVLauncher.exe and then pass it an app key of like "asdasd-123asd-asdd1234" etc etc... so to do that via Citrix selfservice you use the exe box for the txAppVLauncher.exe and then your params are the key... which then leaves you no where to pass in arguments for your real endpoint which for example you want to be notepad.exe but you want to pass notepad a text file path as an argument to auto open... there is no way to do that... at least none that we can find..
anyone have any experience with this ?

Is there a way to execute google apps script from PostgreSQL or from Bash?

I have hundreds of google spreadsheets which all have the same script in them. I'd like to execute a specific google spreadsheet by ID either from PostgreSQL or from Bash. Is there an easy way to execute scripts? I prefer not having to learn python.
For example, I have spreadsheet id 1HGo8V-P5S-z4oCUiAKULrkZRFlzRHEalJqUFLiP and I'd like to execute function Refresh() via Bash or Postgresql.
Is the API the only route? https://developers.google.com/apps-script/api/how-tos/execute
So far my consideration is to create a python executable and execute it from a postgresql function. https://developers.google.com/apps-script/api/quickstart/python
Edit: It looks like if I want to execute any app script, each spreadsheet would need a google project (manually created). There has to be an easier way to do this, manually creating a project for every spreadsheet doesn't make sense.
Reference: https://developers.google.com/apps-script/api/how-tos/execute
The script being called and the calling application must share a Cloud
Platform project.
Solution:
Deploy web apps is the solution I ended up going with thanks to #Tanaike
You want to execute the container-bound script of Spreadsheet.
You want to execute the script from local PC or outside of Google.
You want to execute the script from Spreadsheet ID.
If my understanding is correct, how about this answer?
Retrieving project IDs of container bound script:
I think that this is the difficult problem in your situation. In the current stage, there are no methods for retrieving the project ID of the container-bound script from the parent Google Docs (in this case, it's Spreadsheet.).
This has already been reported at https://issuetracker.google.com/issues/111149037 as a Feature Request. But unfortunately, this has not been achieved yet.
By this, the project IDs are required to be retrieved manually.
For example, you can retrieve the project IDs at Developer Hub.
When you select a project, you can see the project ID at the URL of https://script.google.com/home/projects/### projectId ###.
From above situation, the project IDs are required to be manually retrieved from each Spreadsheet you want to run the script. I apologize that I couldn't find a workaround for this situation.
Executing script:
I think that there are 2 patterns for executing the script. You can select from 2 patterns.
1. Use the method of scripts.run in Apps Script API
This is also mentioned in your question.
Function in the script is execute using API.
You are required to create only python script at local side.
In this case, the access token retrieved by the OAuth2 process is required at local side.
I think that in this pattern, the script can be simple.
2. Use Web Apps
By accessing to Web Apps, function in the script is execute.
In this case, in order to execute the script, it uses scripts.run in Apps Script API, because of large number of Spreadsheets in your situation. When user accesses to Web Apps, the script of Spreadsheet is executed by the script of Web Apps. Because Google Apps Script is used, the access token can be easily retrieved.
You are required to create a python script for accessing to Web Apps at local side, and Google Apps Script at Google Side (Web Apps).
In this case, you can run the script with and without the access token at local side.
I think that in this pattern, the method of access can be simple.
References:
scripts.run method
Web Apps
Taking advantage of Web Apps with Google Apps Script
If this was not what you want, I apologize.
Edit:
From the discussions, I thought that in the case of your script Refresh(), the following flow is suitable.
1. Deploy Web Apps using the script of Refresh() like an API.
2. Call the API using python script and curl.
By this, the script of Web Apps is run and you can reflect the result of Refresh() for all Spreadsheets.
Sample script:
function doGet() {
var spreadsheets = ["spreadsheetId1", "spreadsheetId2",,,]; // Please set spreadsheet ID here.
for (var i = 0; i < spreadsheets.length; i++) {
SpreadsheetApp.openById(spreadsheets[i])
.getSheetByName("Sheet1") // If you want to also put values to other sheet, please modify this.
.getRange(1, 1)
.setValue(new Date());
}
return ContentService.createTextOutput("Done.");
}
When Web Apps is deployed, the authorization screen is opened. But this authorization is only one time.
Deploy Web Apps:
Before you request to Web Apps, please deploy Web Apps.
On the Script Editor
Publish -> Deploy as Web App
Create new Project version
At "Execute the app a"s, select "Me"
At "Who has access to the app", select "Anyone, even anonymous"
Click "Deploy"
Copy "Current web app URL"
Click "OK"
Curl sample:
If you use curl command, please use as follows.
$ curl -L "https://script.google.com/macros/s/#####/exec"
Note:
When you modified the script, please redeploy Web Apps as new version. By this, the latest script is reflected to Web Apps. This is an important point.
Note:
Also you can use the spreadsheet IDs for requesting and you can directly includ them in Web Apps. (In the sample script, the latter is used.)
If you want to use the spreadsheet IDs for requesting, please be careful. The number of workers for Web Apps is required to be less than 30. Ref

KsqlRestClient.makeKsqlRequest("RUN SCRIPT ...") doesn't work without filling ksql.schema.file.content with the script content yourself

In my Scala application, I am trying to tell my KSQL Server that it should execute the RUN SCRIPT <script> command, using the KsqlRestClient.makeKsqlRequest(String ksql) function. Every time I tried it, nothing happened, even though the response was successful, so I started debugging, where I saw that the response was a success but it also returned some kind of error that the property ksql.schema.file.content was empty.
Since I did not find any documentation as to what to fill this property with, I tried some things and eventually found out that if you fill this property with the contents of your .sql file, the run script command works.
Does anybody know if and with what ksql.schema.file.content should normally be filled and/or if the way I am using it is how your supposed to execute a script in KSQL from a Scala application. I already copy and pasted the text from the makeKsqlRequest into the KSQL CLI and everything worked fine, so there should be no error with that.
There is a Github issue tracking the fact that the RESTful API is not documented / supported yet, (as of March 2018).
It sounds like this is something you may want to add a +1 too.

How to run my program on before logout on windows XP?

I am looking for an inverse version of "RunOnceEx".
RunOnceEx does run some program, before the user's shell(desktop&taskbar) start. The login progress will not continue before the runonceex complete.
I want to do exact the same but on user logout.
When she/he logout, all running program shutdown, leaving shell(desktop&taskbar), then ""I wish my program will be execute this moment"", finally logout.
I think it is possible because the "mobsync.exe" is doing that. But I cannot find where and how to do it.
Warning, as said here, gpedit.msc will allow you to configure a logoff script for all users.
If you need that script only for one user, you need to declare it directly in the registry, both in HKCU and HKLM.
To run this only for the current user, you can use WMI to get an information when a shutdown/logout occurs.
Either you write a small C# (or any other language that can use WMI) application or vbs script to listen on the Win32_ComputerShutdownEvent WMI event.
An example C# app can be found here in this question: Get Log off event from system
found in the first result on google for me
To execute a program you can create a script to run it and use group policy to enforce it.
In Group Policy Editor navigate to User Configuration-->Windows Settings-->Scripts (Logon/Logoff)
more information here
If you want a running program to execute code on logoff, then you should hook the WM_QUERYENDSESSION message and look for an lParam value of ENDSESSION_LOGOFF (0x80000000).
It's important to test for this lParam value because the other ones indicate a "forced close" - i.e. your process may be killed before your code is even allowed to run. In fact, most shutdown/session-end messages are only intended to give you an opportunity to run last-minute cleanup code and aren't that safe to respond to with long-running actions; but this particular combination should be OK.
Note: I've never tried to actually run a separate process in response to the WM_QUERYENDSESSION message. It's possible that the window manager will disallow this, like it does during shutdown. Try it and see, I guess.
If you're in a .NET environment (you didn't specify), a quicker way is to add an event handler to the Microsoft.Win32.SystemEvents.SessionEnding event.
What you need is an implementation of GINA. You can run your custom commands in WlxIsLogoffOk function, which gets called when the user initiates a logoff
Once you create the proper GINA dll you can register it here: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\#GinaDLL
Here is an implementation which may fit your needs (it provides a Logoff registry key where you could specify your command):
http://wwwthep.physik.uni-mainz.de/~frink/newgina_pre09/readme.html
As VonC and TFD already mentioned, the Group Policy Editor is just another way to manipulate the registry.
Just make with gpedit the changes (in Userconfig - Windows Settings - Scripts) you like and afterwards take a look in the registry at [HKEY_CURRENT_USER\Software\Policies\Microsoft\Windows\System\Scripts]
to find out how you can do that directly.
Also on my PC (hanging in a domain) is a hidden folder C:\WINDOWS\System32\GroupPolicy with subfolders for user and machine. Both having additional subfolders called Shutdown and Startup. Maybe you can also use these ones.
If you need something simple and working for a single (or any) user you can make a simple application in C++ or C# for example.
The simplest is having a C# in tray (by simply adding the tray component to the form) and register and event handler for the FormClosing event. It'd look like this:
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
if (e.CloseReason != CloseReason.UserClosing)
{
// It's not the user closing the application,
// Let's do whatever you want here, for example starting a process
Process notePad = new Process();
notePad.StartInfo.FileName = "notepad.exe";
notePad.StartInfo.Arguments = "ProcessStart.cs";
notePad.Start();
}
}
So your application will be started with Windows or with the user. It'll wait (using a little bit of memory) and will do something when the system shuts down, or the user log off, etc (by checking "CloseReason" above).