Add start up reg key without run the program - registrykey

I coded a program, which start up on windows start up. My code is this:
public partial class Form1 : Form
{
RegistryKey reg = Registry.CurrentUser.OpenSubKey(#"SOFTWARE\Microsoft\Windows\CurrentVersion\Run", true);//kanei autostart to programma sto anoigma tou upologisti
public Form1()
{
reg.SetValue("Computer Integrity", Application.ExecutablePath.ToString());//computer integrity is the reg key name
reg.Close();
InitializeComponent();
}
Now, the problem is that in order for the program to start, in windows start up, needs to open it first so the key will be registered in the "Registry editor". Is there a way to create a file(.bat for example) in order to register this key to the "registry editor", without needing to open the program ??

You may create the key in regisgry manually and then just export to yourfile.reg file:
https://technet.microsoft.com/en-us/library/cc755091.aspx
Then you can run the regedit from a command line:
regedit.exe /S yourfile.reg
You can also run such a commands from batch file directly via REG ADD command.
Refer here for details: Run reg command in cmd (bat file)?

Related

Open .sln file from cmder?

Is it possible to launch devenv.exe and open a .sln file from cmder? After I clone a git repo from the command line, I'd like to quickly open the solution in Visual Studio without having to leave cmder.
Danny is correct, you simply type xxx.sln.
I'm a bit lazy and developed the script below to be able to type vs and it will find and open the first sln file it finds in the current directory.
Here are some example commands:
vs - Will open the first sln file it finds, if it doesn't find one it will just open Visual Studio without a solution. I default to opening with Visual Studio 2017. Just change the default case in the Get-VisualStudioCommand function if you'd rather default to a different version.
vs 15 - I have a bunch of versions of Visual Studio on my machine, so this will open similarly to vs, but will open with Visual Studio 2015.
vs 13 'helloWorld.sln' - this will open a specific sln file, i.e., helloWorld.sln. One of the projects I worked on recently had multiple solutions in the same directory.
vs -WhatIf -Verbose - this will show you what the script would do if it ran and will print out the Write-Verbose messages. Handy for debugging. I show and example of this in the image below.
For this solution, I'm assuming that you're using a PowerShell console. If so, you can define a .ps1 file that will run before the console opens via the -File option. It's like defining a different PowerShell profile with different commands per console window (very powerful).
See the image below where I show going to settings and modify the PowerShell:PowerShell task to execute PowerShell -NoExit -NoLogo -File C:\src\ps\Cmder\general_setup.ps1 -new_console:d:"C:\src"
Here is the image (note, although I use an alias for ls that outputs in PowerShell like a Linux ls command...this is a PowerShell console):
If you add the following script to the C:\src\ps\Cmder\general_setup.ps1 file (or wherever you want to put it)...you can then type in vs and it will execute. Notice in the Get-VisualStudioCommand function, I've put all the file paths...not the most elegant looking code, but if your file paths to devenv.exe are different than mine, just change them there.
Note, you could also get fancy and add a pass-through to the -ArgumentList or flag for the /SafeMode command to be able to open Visual Studio in safe mode when needed, I've just created these as a quick and dirty shortcut.
function Get-VisualStudioCommand
{
[CmdletBinding()]
param ( [AllowNull()][String] $vsVersion )
$vs10 = """${env:ProgramFiles(x86)}\Microsoft Visual Studio 10.0\Common7\IDE\devenv.exe"""
$vs13 = """${env:ProgramFiles(x86)}\Microsoft Visual Studio 12.0\Common7\IDE\devenv.exe"""
$vs15 = """${env:ProgramFiles(x86)}\Microsoft Visual Studio 14.0\Common7\IDE\devenv.exe"""
$vs17 = """${env:ProgramFiles(x86)}\Microsoft Visual Studio\2017\Professional\Common7\IDE\devenv.exe"""
switch ($vsVersion)
{
'10' {$vs10}
'13' {$vs13}
'15' {$vs15}
'17' {$vs17}
default {$vs17}
}
}
function Get-SolutionName
{
[CmdletBinding()]
param ( [AllowNull()][String] $Name )
if (!$Name)
{
$Name = Get-ChildItem -Filter *.sln
}
if ($Name)
{
$Name = ('"{0}"' -f $Name)
}
return $Name
}
function Start-VisualStudioProcess
{
[CmdletBinding(SupportsShouldProcess=$true)]
param([String]$Version, [String]$Sln)
$VsCommand = Get-VisualStudioCommand -vsVersion $Version
$Sln = Get-SolutionName -Name $Sln
Write-Verbose -Message ('Starting: command={0} solutionName={1}' -f $VsCommand, $Sln)
if ($PSCmdlet.ShouldProcess($VsCommand, 'Start-Process'))
{
if ($Sln)
{
Start-Process -FilePath $vsCommand -ArgumentList $sln
}
else
{
Start-Process -FilePath $vsCommand
}
}
}
Set-Alias -Name vs -Value Start-VisualStudioProcess
Let me know if you have any questions. I hope it helps.
Run this command in your prompt(cmd, cmder, etc.)
reg add "HKCU\Software\Microsoft\Command Processor" /v Autorun /d "doskey vs=for /f \"delims=\" %a IN ('dir /b *.sln') do start %a" /f
Write "vs" for open the first *.sln in folder of Solution and be happy!

Invoke-wmimethod win32_process

Background: I am creating a script to send out a message to everyone in my Domain. I was able to complete this using Invoke-WMImethod and MSG.exe. However, my supervisor wants a more customizable message to be sent. Like changing Color, font size, font style...etc. Which i have created using PowerShell.
Script:
Invoke-WmiMethod -ComputerName $Computer -Class Win32_Process -Name Create -ArgumentList {"C:\x\x\x\Powershell.exe -File `"\\Server\Share\Folder\Script.ps1`""}
When i run this script against my Computer it works perfectly. However, when i attempt to run it on a remote computer it fails.
I don't understand why.
It's the same exact script that i used with MSG.exe, which worked, but it still doesn't work with a powershell script.
I attempted to copy the script to the remote computers 'C:\' and run it from that file path but it still didn't work.
I've verified the file path to Powershell.exe is the same as the script and that the remote workstation can access the .PS1 Script.
However, the script does run and says it is successful with a Return Value of 0. Example:
__GENUS : 2
__CLASS : __PARAMETERS
__SUPERCLASS :
__DYNASTY : __PARAMETERS
__RELPATH :
__PROPERTY_COUNT : 2
__DERIVATION : {}
__SERVER :
__NAMESPACE :
__PATH :
ProcessId : 8748
ReturnValue : 0
My Suggestion would be to check for the versions on both the machines. The CmdLet you using may not be working on the previous version.
I again have a suggestion to make, you can use the below command to get your work done, if you have powershell Version 3 or above.
$Outputreport = "Test message to send data using port 443"
[System.Net.ServicePointManager]::ServerCertificateValidationCallback = { $true }
$wc = new-object System.Net.WebClient
Invoke-RestMethod -Method Post https://hostnamedotcom/cgi-bin/dir-path/$hostname-filename -Body $Outputreport

How do I run a .lua script in Notepad++?

I have a very basic .lua file saved in a folder, with just the code
print("Hello world")
I additionally have the standalone lua interpreter downloaded, but it is beyond me how to successfully run my code. I put all the files of the interpreter in the same folder but when I use F5 to run the program I see no text in the interpreter.
Run Notepad++.
On the menu select: Run -> Run.. (F5).
Insert: C:\path\to\lua.exe "$(FULL_CURRENT_PATH)"
Now you can run your scripts by pressing F5 on your keyboard.
Just do it with NppExec plugin:
SET interpreter = F:\lua\lua53.exe
SET exec = "$(interpreter)" "$(FULL_CURRENT_PATH)"
NPP_SAVE
$(exec)
if $(EXITCODE) != 0 goto exit
NPP_CONSOLE 0
NPP_RUN cmd /C "cmd /C $(exec) && pause"
:exit
KaMehHb's answer is correct, but one thing to add is either delete this line or change it to 1 if you want the console to stay up.
NPP_CONSOLE 0
to
NPP_CONSOLE 1

Deploying an OVF/OVA file

Deploying an OVF/OVA file to a remote ESXi server
I am trying to deploy an OVF/OVA file to a remote ESXi server.
I want to do this from the command line.
I have written a simple batch file which deploys the ovf using
ovftool.exe.
Here is my batch file:
#echo off
CLS
set OVF_COMMAND="C:\Program Files (x86)\VMware\VMwareWorkstation\OVFTool\ovftool.exe"
set OVF_DEPLOY_OFF=ovftool
IF NOT EXIST %OVF_COMMAND% (
#echo powershell does not exists at:
#echo %OVF_COMMAND%
pause
)
#echo START OF THE BATCH SCRIPT
#echo ###############**strong text**########################################################
%OVF_DEPLOY_OFF% --noSSLVerify --disableVerification --skipManifestGeneration C:\Newfolder\vAppTS2\vAppTS2.ovf vi://administrator:jim#141.192.91.124/nrtms-training/host/141.192.91.9/
#echo #######################################################################
This works fine, but it is too slow. The OVF file comprises of one vApp with one VM. When all will be done the vApp will contain about 9 VMs.
It takes about 20 minutes to deploy the the current vApp which contains only one VM. I cannot imagine how long it will take to deploy a vApp with 9 VMs.
Is it a way to make it faster?
Cheers.
I have managed to find work-around.
Instead of importing a ovf file from some remote location I have chosen to clone that vApp from a predefined resource pool.
So at the beginning I have created a resource pool on which I have uploaded a vApp.
//connect to server
Connect-VIServer -Server $args[2].ToString() -Username $args[3] -Password $args[4]
// search which vApp to move into the new source pool
// The name of the vApp is given as an argument to the powerCLI script
// It must be one of the existing vApps
foreach ($vApps in (Get-vApp ) )
{
if ($vApps.name -eq $args[0])
{
# defined source and destination hosts
$vmHost_dest = Get-VMHost -Name "100.106.37.10"
$vmHost_source = Get-VMHost -Name "100.106.37.9"
# create a resource pool on destination host
$myDestinationRP = New-ResourcePool -Name "datastore-13" -Location $vmHost_dest
New-VApp -Name MyVApp2 -VApp $vApps -Location $myDestinationRP
}
}
So I can build a custom vApp and store it to a specific source pool from where I can clone it later on as I please.
If I want to remove the newly cloned vApp I can do as followS:
Get-VApp $vApps | Remove-VApp -Confirm:$false
Hope this helps

How to install application as windows service using NSIS script

How to install application as windows service using NSIS script?
I used this command in the script Exec '"sc.exe" but after installation i couldn't find any service in windows services related to it so help me thanks.
Maybe that the NSIS Simple Service plugin can help you. The syntax is as simple as
SimpleSC::InstallService "MyService" "My Service Display Name" "16" "2" "C:\MyPath\MyService.exe" "" "" ""
Pop $0 ; returns an errorcode (<>0) otherwise success (0)
Here the example install the service as ServiceType own process + StartType automatic + NoDependencies + Logon as System Account.
Please refer to the accompanying help for the meaning of the magic numbers.
The wiki shows the 5 other methods to handle services with NSIS.
There are multiple plugins out there as stated on NSIS website
For me it seemed to be unnecessary complicated, so I ended up using sc tool directly. A command is quite simple:
!define appName "theApp.exe"
!define displayName "My Awesome Service"
!define serviceName "MyAwesomeService"
ExecWait 'sc create ${serviceName} error= "severe" displayname= "${displayName}" type= "own" start= "auto" binpath= "$INSTDIR\${appName}"'
A full list of sc create arguments available here
Below is the scripts which first stops service, uninstalls previous version, remove form registry and then installs fresh copy.
Section "Mobile Interface"
SimpleSC::StopService "MobileInterface" "1" "60"
SimpleSC::RemoveService "MobileInterface"
DeleteRegKey /ifempty HKLM "MobileInterface"
RMDIR /r "$INSTDIR\MobileInterface\"
SetOutPath "$INSTDIR\MobileInterface"
# define what to install and place it in the output path
File "D:\NCS.Sentinel\NCS.Sentinel.MobileWebSvc\bin\Release\"
SimpleSC::InstallService "MobileInterface" "MobileInterface" "16" "2" "$INSTDIR\MobileInterface\NCS.Sentinel.MobileWebSvc.exe" "" "" ""
Pop $0 ; returns an errorcode (<>0) otherwise success (0)
SimpleSC::StartService "MobileInterface" "" "100"
#WriteRegStr HKLM "D:\NCS.Sentinel\NCS.Sentinel.MobileWebSvc\bin\Release\NCS.Sentinel.MobileWebSvc.exe"
WriteUninstaller "$INSTDIR\Uninstall.exe"
; Store installation folder
;WriteRegStr HKCU "Software\Mobile Interface" "" $INSTDIR
SectionEnd

Resources