w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML Categories
Creating powershell script to get show on desktop enabled + rename with hostname
Changing HKCRCLSID{20D04FE0-3AEA-1069-A2D8-08002B30309D}LocalizedString is still suitable on Server 2008 R2, but you need to take ownership of the key and grant administrators full access to it first.

Categories : Powershell

i need to copy and then rename the copy of a file if it already exists
Try this code, let me know if it works Function <?php function recursive_naming( $file, $i = 1 ) { $dirname = dirname( $file ).DIRECTORY_SEPARATOR; $filename = pathinfo( $file, PATHINFO_FILENAME ); $extension = pathinfo( $file, PATHINFO_EXTENSION ); if ( !file_exists( $file ) ) { return $file; } $filename = preg_replace( '/_d+$/', '', $filename ); $file = $dirname.$filename."_".$i.".".$extension; $i++; return recursive_naming( $file, $i ); } ?> Example: <?php $pastaTemp = $_FILES['imagem_principal']['tmp_name']; $pastaUpload = $_SERVER['DOCUMENT_ROOT']."/casaunica/imagens/acabamentos/"; $arquivo = recursive_naming( $pastaUpload.$_FILES['imagem_principal']['name'] ); ?> It will output filename_2.jpg if fi

Categories : PHP

C# WCF impersonation not working for powershell script invoked from webservice hosted on IIS(WIn 2012)
As an alternative approach you could try to psexec your request: C:>psexec -s -u {user} -p {password} cmd /c mkdir c: est est123 psexec will remotely run as the user with full privileges, without using impersonation. You will need to download put psexec and put it somewhere available to IIS.

Categories : C#

Powershell - User Mapping SQL Server 2012
Supposing your login is created ## Creating database user and assigning database role #get variables $instanceName = "yourInstance" $loginName = "testLogin" $dbUserName = "testUserName" $databasename = "tempdb" $roleName = "db_backupoperator" $server = New-Object -TypeName Microsoft.SqlServer.Management.Smo.Server -ArgumentList $instanceName #add a database mapping $database = $server.Databases[$databasename] $login = $server.Logins[$loginName] if ($database.Users[$dbUserName]) { $database.Users[$dbUserName].Drop() } $dbUser = New-Object ` -TypeName Microsoft.SqlServer.Management.Smo.User ` -ArgumentList $database, $dbUserName $dbUser.Login = $loginName $dbUser.Create() #assign database role for a new user $dbrole = $database.Roles[$roleName] $dbrole.AddMember($dbUserName) $dbr

Categories : SQL

Powershell file-rename 20130702 into 2013-07-02
Use the Insert method to add dashes at specific locations and remove _foo: Get-ChildItem *_foo.pdf | Rename-Item -NewName { $_.Name.Insert(4,'-').Insert(7,'-') -replace '_foo' }

Categories : Powershell

Developing C# Winforms software using SQL Server 2012 in Visual Studio 2012 and running it on other system without installing SQL Server 2012
If you develop an application that use Sql Server 2012 as storage for your data then you need to install it in a way or another. There are numerous versions of Sql Server, like Sql Server Express and LocalDB. In every case you need the bits that supports your coding calls. This magazine article summarizes relevant infos on the various version of Sql Server I suppose that the right product for you is Sql Server LocalDB. A version of Sql Server that could be distributed easily with your application setup and doesn't require a complex installation procedure. However, if you don't foresee the need to escalate you application to a full Client-Server model and you need only a local storage for a single user, you could choose a single file database like Sql Server Compact Edition or SQLite or

Categories : C#

Batch File to Copy and Rename SQL Backup File created Today
if %mydate2%==%mydate% RENAME %%I DBRestore.bak DO COPY %%I E:DataRestore & exit /b The above lines are not valid batch syntax. You cannot have an if with a condition, but no action. You cannot use loop variables (%%I) outside a loop. do is only a valid keyword in for loops. Also, you don't need to determine the current date via date /t. There's a variable %DATE% providing that information. Your script should probably look somewhat like this: @echo off setlocal EnableDelayedExpansion echo deleting previous file..... del E:DataRestoreDBRestore.bak /f set mydate2=%DATE:~10,4%%DATE:~4,2%%DATE:~7,2% for /F %%I in ('dir /B /O:D *.bak') do ( set "filename=%%~fI" set "temp=%%~tI" set "mydate=!temp:~6,4!!temp:~0,2!!temp:~3,2!" echo last modified file date is !mydate!

Categories : Batch File

Copy and Rename newest file
Try something like this for copying the newest file from a folder: @echo off setlocal set "src=C:UserClient1ReportsReportFolderA" set "dst=C:UserClient1FinalReports" pushd "%src%" for /f "delims=" %%f in ('dir /b /a:-d /o:-d') do ( copy "%%~f" "%dst%File1.csv" goto next ) :next popd In VBScript you could use the Shell.BrowseForFolder method for selecting a folder. Example for selecting the source folder: Set os = CreateObject("Shell.Application") basedir = os.Namespace("C:").Self.Path Set fldr = os.BrowseForFolder(0, "Select source folder:", &h10&, basedir) If fldr Is Nothing Then WScript.Echo "User pressed [Cancel]." WScript.Quit 1 End If src = fldr.Self.Path Finding and copying the most recent file in a folder can be achieved like this: Set fso = CreateObje

Categories : Windows

Installing Windows Features on remote server 2012 using powershell 3.0
Personally I would use the latter (directly call Install-WindowsFeature -ComputerName $server rather than do a separate Invoke-Command) in this case for the following reasons: You may be hard-coding the feature names now, but in the future you may want to put those in a variable. If you put them in a variable, you'll have to pass it as a parameter into the Invoke-Command's script block. This is entirely possible, but more work. By using your own loop, you can write progress messages, logging, etc. You gain nothing by using Invoke-Command in this case because you're running a single command on the remote computer (as opposed to running multiple commands with -ComputerName parameters vs. running multiple commands inside the script block).

Categories : Powershell

How to properly -filter multiple strings in a PowerShell copy script
use the include is the easiest way as per http://www.vistax64.com/powershell/168315-get-childitem-filter-files-multiple-extensions.html

Categories : Powershell

Python copy files to a new directory and rename if file name already exists
I would say you have an indentation problem, at least as you wrote it here: while not os.path.exists(file + "_" + str(i) + extension): i+=1 print "Already 2x exists..." print "Renaming" shutil.copy(path, file + "_" + str(i) + extension) should be: while os.path.exists(file + "_" + str(i) + extension): i+=1 print "Already 2x exists..." print "Renaming" shutil.copy(path, file + "_" + str(i) + extension) Check this out, please!

Categories : Python

PHP move/copy temp file into a new directory and rename it ( performance )
Move would be as faster than copy... To move a file use the rename function. To move an uploaded file move_uploaded_file is the way to go. It has a little overhead in that it check and ensures that the file was in fact the result of an upload.

Categories : PHP

Copy query output data from SQL SERVER 2012 and paste to Excel
Use Excel Import from SQL Server feature. It should import each row of data into a single row in Excel and each column into a single column.

Categories : Sql Server

script for accessing remote server, get error log and rename it automatically.
The easiest way to accomplish this would be to setup an automated job on Gorilla4. Your first problem, is that you'll need to setup password-less SSH access between Gorilla4 and Monkey so you don't need a person to physically type in the password. While you can do this with the 'root' user I would STRONGLY recommend against it. Instead create a maintenance user on BOTH hosts: $ useradd -m maintuser Then switch to the new user and create SSH key on Gorilla4: $ ssh-keygen -t rsa -b 2048 Accept the defaults when prompted. Then copy the id_rsa.pub file to the ~/.ssh directory of the maintuser on Monkey. Now, when you are the "maintuser" on Gorilla4, you can SSH to Monkey without a password. Then you can create a script called "copy_log.sh": #!/bin/bash # copy_log.sh log_path="/pa

Categories : Shell

PowerShell batch file to toggle show touch input panel
This should work: # Settings $ProcessName = "TabTip" $Executable = "C:Program FilesCommon Filesmicrosoft sharedinkTabTip.exe" # Get process $Process = Get-Process -Name $ProcessName -ErrorAction SilentlyContinue # Is it running? If($Process) { # Running # Kill this process $Process.Kill() } Else { # Not running # Start the process Start-Process $Executable } I have tried killing it with Stop-Process $Process aswell as with Stop-Process $Process.Id but I'm always getting an access denied (not sure why). However, the Kill() method worked fine, you should use this

Categories : Windows

Using Shell script and sed - Find and replace a word in file and rename file
I guess you are making it complex: why not make it simple with two simple satements. Its up to you how you use the below statements for your purpose: perl -pi -e 's/wordtofind/wordtoreplace' your_file #for replacing the word in the file mv your_file wordtoreplace #for renaming the file

Categories : Shell

create windows 8 batch file to copy, rename and save files from sub directories recursively
@ECHO OFF &SETLOCAL SET "startfolder=C:pictureskitcam" SET "targetfolder=C:pictureskitcamall" FOR /r "%startfolder%" %%a IN (*.jpg) DO ( SET "fname=%%~nxa" SET "fpath=%%~fa" FOR /f "delims=" %%b IN ("%%~dpa.") DO SET "nname=000%%~nxb" SETLOCAL ENABLEDELAYEDEXPANSION ECHO MOVE "!fpath!" "%targetfolder%!nname:~-4!_!fname!" ENDLOCAL ) Look at the output and remove the word echo before move if it looks good.

Categories : Windows

Copy/transfer file using PowerShell 2.0
One of the nice things about PowerShell is (unlike DOS) it support UNC paths. So you can literary just do: Copy-Item -Path <local file path> -Destination \<server IP><share><path> Of course your account will need to have access to that location. If you need to enter alternate credentials you can pre-authenticate using net use \<server IP><share> /user:[<domain>]<user> <password>

Categories : Powershell

Photoshop Javascript script: Rename file and saveAs
Try to use forward slashes in your docPath: var docPath="C:/Users/user/Desktop/test"; (tab) and u (beginning of a Unicode sequence) have special meanings in JS strings. Or you can escape them, of course: var docPath="C:\Users\user\Desktop\test";

Categories : Javascript

Copy-item Files in Folders and subfolders in the same directory structure of source server using Powershell
This can be done just using Copy-Item. No need to use Get-Childitem. I think you are just overthinking it. Copy-Item -Path C:MyFolder -Destination \ServerMyFolder -recurse -Force I just tested it and it worked for me.

Categories : Powershell

how to rename a file while uploading it to the server?
String pathvalue; protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (resultCode == RESULT_OK) { if (requestCode == SELECT_FILE) { Uri selectedImageUri = data.getData(); String tempPath = getPath(selectedImageUri, ServiceEntry.this); Bitmap bm; System.out.println(tempPath); File filename = new File(tempPath); pathvalue = filename.getAbsolutePath() } } } public String getPath(Uri uri, Activity activity) { String[] projection = { MediaColumns.DATA }; Cursor cursor = activity .managedQuery(uri, projection, null, null, null

Categories : Android

Ruby mass rename script not finding text or csv for file renaming
Will ARGV[0] search for any text or csv file in the same directory? No, ARGV[0] is just the first argument that you pass to the script. For this script to work it looks like you'll need to run the script with the csv file you want to use as its first argument, and you'll have to be in the directory that contains the files you want renamed. For example, cd /path/to/png_files ./mass_rename_script.rb file_with_stuff_to_rename.csv

Categories : Ruby

PowerShell script to copy two files from a static location to a location with two variables in the in path
First of all create CSV with structure like below (users.csv): Name,Sip login1,login1@gmail.com The run following statement: Import-Csv C:PATH_TO_CSVusers.csv | foreach{cp C:YOUR_PATHYOUR_FILE ("C:Users"+$_.Name+"AppDataLocalMicrosoftCommunicator"+$_.Sip)} Update Script for run for current user: $userName = [Environment]::UserName; $domain = [Environment]::UserDomainName; # Look for a user $Rech = new-object System.DirectoryServices.DirectorySearcher $rc = $Rech.filter = "((sAMAccountName=$userName))" $rc = $Rech.SearchScope = "subtree" $rc = $Rech.PropertiesToLoad.Add("mail"); $rc = $Rech.PropertiesToLoad.Add("msRTCSIP-PrimaryUserAddress"); $theUser = $Rech.FindOne() Write-host "Username is" $userName Write-host "Domain is" $domain if ($theUser -ne $null) { Write-Host "Mail is"

Categories : Powershell

Window Server 2012 & SQL Server 2012 within single VM on Windows Azure
Arun Rana, That should be possible and AFAIK there isn't any restriction for SQL Server licence to be used in Azure, however take a look at License Mobility through Software Assurance on Windows Azure. If your licence is from MSDN, then it now absolutely legal use it on Azure. If you are unsure about the licence problem and other litigation, you may spin up a VM with SQL Server 2012 pre-installed and this will solve your licence trouble (but right now only available with the combo of SQL Server 2012 on Windows Server 2008 R2). PS / Personal Experience : SQL Server + some server component isn't performing well for a Medium instance. Either split the server roles or consider choosing a bigger instance size like xLarge or A6.

Categories : Azure

Simple PowerShell Script to loop through 1 CSV file to create a new CSV file from another
Borrowing Shay's awesome CSV field enumeration code: $offices = Import-Csv 'C:path ooffices.csv' Import-Csv 'C:path ousers.csv' | % { foreach ($prop in $_.PSObject.Properties) { $offices | select @{n=$prop.Name;e={$prop.Value}}, OFFICES } } | Export-Csv 'C:path ocombined.csv' -NoTypeInformation

Categories : Powershell

Invoke one PowerShell script from Another PowerShell script with passing arguments
PS C:> gc . est2.ps1 . est1.ps1 'foo' Write-Host 'bar' PS C:> gc . est1.ps1 $a = $ARGS[0] -split '' [array]::Reverse($a) Write-Host ($a -join '') PS C:> . est2.ps1 oof bar

Categories : Powershell

Visual studio 2010 with sql server 2008 (default with vs10) and sql 2012. How can I choose from 2008 or 2012 while adding database in server explorer?
After the project is created: Open the database project's properties. Go to the Project Settings tab. Change "Target platform" to SQL Server 2008 or whichever option you need.

Categories : Sql Server

Powershell script to create an xml file
You can try and pipe to the ConvertTo-Xml cmdlet. Here's how the output looks like for 3 process objects. You can then pipe it out to a file : PS> gps | select name,id -first 3 | ConvertTo-Xml -As String -NoTypeInformation <?xml version="1.0"?> <Objects> <Object> <Property Name="Name">AppleMobileDeviceService</Property> <Property Name="Id">1568</Property> </Object> <Object> <Property Name="Name">audiodg</Property> <Property Name="Id">5140</Property> </Object> <Object> <Property Name="Name">Babylon</Property> <Property Name="Id">4908</Property> </Object> </Objects>

Categories : SQL

SQL Server Express 2012 Installation fails with Could not find the Database Engine startup handle in SQL Server Express 2012
I have found the solution. It was, in fact, a r/w rights error. I have added following users to my profile folder: IUSR Local Service Network IIS_IUSRS Service I know I went overkill here but I wanted to be sure without giving everyone access rights. I will disable them one by one and find the right one(s) needed to properly run SQL Server Express 2012.

Categories : Misc

powershell script too slow (file enumeration)
Get-ChildItem may be slowish (though it appears to be about twice as fast in PowerShell 3 as it was in v2), write-host is slowing you down a lot too. On a directory structure containing 27000+ files, the following code ran in 16.15 seconds vs 21.08 seconds for your code. On a smaller directory containing about 2400 files, it was 1.15s vs 1.22s. gci $path -file -Recurse | select @{name="fpath";expression={$_.fullname.replace($src,"").replace("","/")}},lastwritetime,@{Name="size";Expression={$_.length}},@{Name="id";Expression={$_.basename}}| select id,size| ConvertTo-Json The resulting JSON doesn't have the header yours does, but you should be able to handle that after the fact.

Categories : Powershell

script file: name editing and renaming using PowerShell
You can use Get-Child item with recursive option to load all the jpg files and rename it using Rename-item command. Get-ChildItem -r -path "C: est" *.jpg | % { if(!$_.PSIsContainer -and $_.Name.Contains('_')) {Rename-item $_.FullName ( $_.BaseName.Split('_')[1] +"p" + $_.Extension) } }

Categories : Windows

SQL Log File Not Shrinking in SQL Server 2012
The situation as you describe it seems fine. A transaction log backup does not shrink the log file. However, it does truncate the log, file, which means that space can be reused: From Books Online (Transaction Log Truncation): Log truncation automatically frees space in the logical log for reuse by the transaction log. Also, from Managing the Transaction Log: Log truncation, which is automatic under the simple recovery model, is essential to keep the log from filling. The truncation process reduces the size of the logical log file by marking as inactive the virtual log files that do not hold any part of the logical log. This means that each time the transaction log backup occurs in your scenario, it's creating free space in the file which can be used by subsequent tra

Categories : SQL

How to import an XML file into SQL Server 2012
Use SSIS. Create an SSIS package with an XML data source. If you can't use/don't have integration services, use UNC file paths to eliminate local/network standpoint issues. Edit:I failed to exercise google-fu prior to shooting off at the mouth and one of my initial ideas was incorrect.

Categories : SQL

How to copy file from one server to another server in node js using webDAV protocol?
You can try with node module - poster for directly upload to server Stream local file var poster = require('poster'); var options = { uploadUrl: 'http://mysite.com/upload', method: 'POST', fileId: 'file', fields: { 'myfield': 'value', 'myfield2': 'value2' } }; poster.post('file.jpg', options, function(err, data) { if (!err) { console.log(data); } }); Stream remote file var poster = require('poster'); var options = { uploadUrl: 'http://mysite.com/upload', method: 'POST', fileId: 'file', fields: { 'myfield': 'value', 'myfield2': 'value2' } }; poster.post('https://www.google.com/logos/2012/addams11-hp.jpg', options, function(err, data) { if (!err) { console.log(data); } });

Categories : Node Js

Copy file from internal server to remote server in IIS 7
try convert virtualpath to phyicalpath in a handler, such as system.web.httpserverUtil.mappath http://asp.net.bigresource.com/Uploading-files-to-server-and-saving-outside-virtual-path-bMVjFTYf4.html#l9LpkWyji http://forums.iis.net/t/1157234.aspx

Categories : C#

Powershell script can't find module when run via -File param
I'm dumb :P There is a dropdown in TeamCity where you can select the runmode of x86 or x64. It was set to x86. I changed it to x64. Now it executes under the correct version. Still curious why the modules wouldn't load in x86 though... Also, it's weird that SysWOW64 correlates to x86 and System32 correlates to x64

Categories : Powershell

Powershell - move and rename
try this: http://technet.microsoft.com/en-us/library/ee176940.aspx go to the folder where the file is you want to rename and than type this: Rename-Item 14283963_5206074553_17052013-9102945.pdf 5206074553.pdf

Categories : Powershell

I can't restore database from .bak file in SQL Server 2012
I found the same issue and the issue for me was that files were created by another user and permissions were not properly allocated. Try updating the Login for the SQL Server Service to an Administrator on the box.

Categories : Misc

Need a powershell script to use a parameter to manipulate/read in fields from another csv file
You can react to the server name like this: $csv = Import-Csv 'C:path oyour.csv' ... if ( $alert.PrincipalName -eq 'MYSTSERVER.CONTOSO.COM' ) { if ( $alert.MonitoringObjectDisplayName -match '.*[(.*?)]' ) { $targetserver = $matches[1] } } else { $targetserver = $alert.PrincipalName } $newdata = $csv | ? { $_.ServerName -eq $targetserver } ` | select ServiceOwner, 'Application Tier' ... $alert.CustomField2 = $newdata.ServiceOwner $alert.CustomField3 = $newdata.'Application Tier' ...

Categories : Powershell

PowerShell - How to execute script and save results in text file
If you want to sample every 2 seconds, and show max,min,ave for the whole period that cmd.exe is running then the code below will work. But if you want to sample the data every two seconds and show the max,min,ave for that 2 second interval then all 3 will be the same (because you only have 1 sample during that interval). You'll have to sample more frequently (like every .2 seconds) and then reset the $stats array after every two second interval. The code below isn't designed for that. $cmdProcess = start-process cmd -passthru $delay = 2 $stats = @() $previous = ($cmdProcess|Get-Process).cpu while (-not $cmdProcess.HasExited) { $latest = $cmdProcess|Get-Process $delta = $latest.cpu - $previous $delta $stats += $delta $previous = $latest.CPU sleep $delay } $stats|% {$_/$delay}

Categories : Powershell



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.